flyter  

1.在第二个界面的.h文件中申明block

@property(nonatomic,copy)void(^myBlock)(NSString * str);

2.在返回第一个界面的点击事件中赋值要传递我的信息,一定要对myBlock初始化,否则在第一个页面中不会运行block语句内部代码。

-(IBAction)backBtnClicked:(id)sender{
   
        self.myBlock(@"我来自第二个界面");
    
    [self dismissViewControllerAnimated:YES completion:nil];
}
3.在第一个界面的跳转事件中,在block中可以得到传递的信息

-(IBAction)btnClicked:(id)sender{
    SecondViewController * SVC = [SecondViewController new];
    SVC.myBlock = ^(NSString *str){
        NSLog(@"%@",str);
    };
    [self presentViewController:SVC animated:YES completion:nil];
}

posted on 2016-06-16 15:33  flyter  阅读(161)  评论(2)    收藏  举报