a到b的顺传 ios
2016-04-13 00:08:58 Arodung 阅读数 929

每天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的博客

2016-05-31 23:31:00 weixin_34413065 阅读数 9
1677850-3e98f5572c85fa6e.png
1677850-f3271eff4849f0a6.png
1677850-1d5ab4874cef3652.png

博文 来自: weixin_34306676

ios拍传

阅读数 1172

没有更多推荐了,返回首页