@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];