SecondViewController.h
#warning第一步
//在第二个页面里声明block属性
@property(nonatomic,copy)void(^secondBlock)(NSString*str);
SecondViewController.m
-(void)didClickButton:(UIButton*)button{
#warning第二步
//在第二个页面里执行block回调,将@"路飞"传给第一个页面
self.secondBlock(@"路飞");
[self.navigationControllerpopViewControllerAnimated:YES];
}
RootViewController.m
-(void)didClickButton:(UIButton*)button{
SecondViewController* sec = [[SecondViewControlleralloc]init];
#warning第三步
//在第一个页面中实现block
//block回调
//得到block回传的string并赋给label
sec.secondBlock= ^(NSString* string){
self.label.text= string;
};
[self.navigationControllerpushViewController:secanimated:YES];
}
SecondViewController.m
-(void)dealloc{
#warning第四步
//Block释放
Block_release(_secondBlock);
[_textFieldrelease];
[superdealloc];
}