干货:
咱们分为1页2页,情况是1页向2页跳,2页往1页传值 1页得到传回的值
首先在2页的.h ,定义block
#import <UIKit/UIKit.h>
typedef void(^changeType)(NSString *);
@interface firstViewController : UIViewController
@property(nonatomic, copy)changeType callBackBlock;
@end
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSString *str = @"我是一个小红帽";
self.callBackBlock(str);
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
firstViewController *firVC = [[firstViewController alloc] init];
firVC.callBackBlock = ^(NSString *str){
NSLog(@"%@",str);
};
[self presentViewController:firVC animated:YES completion:nil];
}
这样就得到需要的值了.