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