/**A : .m*/
#import “controllerA.h”
#import "controllerB.h”
@interface controllerA ()
@property (nonatomic, strong) UITextField *textFieldA;
@property (nonatomic, strong) UIButton *buttonA;
@implementation controllerA
部分代码…………省略
按钮的跳转事件
- (void)buttonClick:(UIButton *)buttonA{
controllerB *controller =[[controllerB alloc]init];
controller.returnTextBlock = ^(NSString *showText){
self.textFieldA.text = showText;
};
[self presentViewController:controller animated:YES completion:nil];
}
@end
/**B : .h*/
#import <UIKit/UIKit.h>
typedef void(^ReturnTextBlock)(NSString *showText);
@interface controller : UIViewController
@property (nonatomic, copy) ReturnTextBlock returnTextBlock;
@property (nonatomic, strong) UITextField *textFieldB;
@end
/**B : .m*/
#import “controllerA.h”
#import "controllerB.h”
@interface controllerB ()
@property (nonatomic, strong) UITextField *textFieldB;
@property (nonatomic, strong) UIButton *buttonB;
@implementation controllerB
部分代码…………省略
按钮的跳转事件
- (void)buttonClick:(UIButton *)buttonB{
if (self.returnTextBlock) {
self.returnTextBlock(self.textFieldB.text);
}
[self dismissViewControllerAnimated:YES completion:nil];
}
@end