block逆传值页面间的

2016-10-14  本文已影响0人  xh_0129

@interface SecondViewController : UIViewController

@property (nonatomic,copy) void(^stringBlock)(NSString *text);

@end

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {

[super viewDidLoad];

UIButton *b = [[UIButton alloc]initWithFrame:CGRectMake(60, 80, 100, 32)];

b.backgroundColor = [UIColor blueColor];

[b addTarget:self action:@selector(pop) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:b];

}

- (void)pop {

//传值

self.stringBlock(@"第二个值");

[self.navigationController popViewControllerAnimated:YES];

}

//需要接受值的地方,即push到SecondViewController的地方

SecondViewController *send = [[SecondViewController alloc]init];

send.stringBlock = ^(NSString *text) {

label.text = text;

NSLog(@"%@",label.text);

};

[self.navigationController pushViewController:send animated:YES];

上一篇 下一篇

猜你喜欢

热点阅读