iOS 通知传值(顺传)

来源:互联网 发布:ubuntu开机花屏 编辑:程序博客网 时间:2024/03/29 18:59

每天10点下班,没有加班费,没有补助,请假还扣工资,这日子没法过了,日子没法过了,但是要不断复习前面的知识,否则,她就和你@“分手”;

接下来我把通知传值得方法复习一下,虽然简单,但是实用;

少说废话,上代码:

首先有两个控制器:

ViewController SecondViewController;实现将 ViewController里面的值传到 SecondViewController 


ViewController.h

#import "ViewController.h"#import "SecondViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];}- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{    SecondViewController *secondVC = [[SecondViewController alloc] init];    [self presentViewController:secondVC animated:YES completion:nil];    [[NSNotificationCenter defaultCenter] postNotificationName:@"SecondViewControllerCenter" object:@"AirZilong"];}

SecondViewController.h

#import "SecondViewController.h"@interface SecondViewController ()@end@implementation SecondViewController- (void)viewDidLoad {    [super viewDidLoad];    self.view.backgroundColor = [UIColor greenColor];    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getObjecgt:) name:@"SecondViewControllerCenter" object:nil];}- (void)getObjecgt:(NSNotification *)notification{    NSLog(@"notification.object = %@",notification.object);}

打印结果:

2016-04-13 00:16:07.025 Test-Notification[8044:68675] notification.object = AirZilong


如果转载请注明转于:AirZilong的博客

3 0
原创粉丝点击