//在B頁面的.h中寫一個指針函數(shù)(結構體),帶參數(shù),用戶進行傳值
//在B頁面的.h中聲明一個指針類型的變量
//例如:
import <UIKit/UIKit.h>
@interface BViewController : UIViewController
typedef void(^PostString)(NSString *str);//定義一個指針函數(shù)
@property (nonatomic,copy)PostString mblock;//定義一個結構體對象
//在B頁面的.m中Button對象的方法中使用block函數(shù)
- (void)buttonAciton{
//打印返向傳值
NSLog (@"反向傳值");
if (self.mblock) {
self.mblock(self.textField.text);
}
[self dismissViewControllerAnimated:YES completion:nil];
}
//在A頁面的.m中中Button對象的方法中使用block函數(shù) - (void)buttonAciton{
AViewController * vc = [[AViewController alloc]init];
//block變量的值等于B頁面穿過來的值
vc.mblock = ^(NSString * str) {
self.textField.text = str;
};
//模態(tài)推出下一頁
[self presentViewController:vc animated:YES completion:nil];
}