SecondViewController.h
#warning第一步
//在第二個(gè)頁(yè)面里聲明block屬性
@property(nonatomic,copy)void(^secondBlock)(NSString*str);
SecondViewController.m
-(void)didClickButton:(UIButton*)button{
#warning第二步
//在第二個(gè)頁(yè)面里執(zhí)行block回調(diào),將@"路飛"傳給第一個(gè)頁(yè)面
self.secondBlock(@"路飛");
[self.navigationControllerpopViewControllerAnimated:YES];
}
RootViewController.m
-(void)didClickButton:(UIButton*)button{
SecondViewController* sec = [[SecondViewControlleralloc]init];
#warning第三步
//在第一個(gè)頁(yè)面中實(shí)現(xiàn)block
//block回調(diào)
//得到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];
}