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