在ViewController2中咱们写block定义:函数
#import <UIKit/UIKit.h> typedef void (^ReturnTextBlock)(NSString *showText); //为要声明的Block从新定义了一个名字 @interface Page1 : UIViewController @property (nonatomic, copy) ReturnTextBlock returnTextBlock; //将一个block当作一个属性来用 @end
- (IBAction)touchCancel:(id)sender { if (self.returnTextBlock != nil) { self.returnTextBlock(@"2323223"); //用block回传值 } [self dismissViewControllerAnimated:YES completion:nil]; }
在ViewController1界面中,UIButton的点击代码:
atom
Page1 *tfVC = segue.destinationViewController; tfVC.returnTextBlock = ^(NSString *showText) { self.label1.text = showText; };