简单实现代理传值
2018-12-19 本文已影响0人
来根黄鹤楼啊
用代理反向传值
在想要的类传值的里面
@protocol oneViewControllerDelegate<NSObject>//定义了一个协议
- (void)changeBgColor:(UIColor*)color;//用这个方法进行回调传值
@end
@interfaceoneViewController :UIViewController
@property (nonatomic,retain) id<ConfigViewControllerDelegate> delegate;//协议中的代理
@end
上面是页面B
下面是页面A
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event{
oneViewController *one = [oneViewController new];
one.delegate=self;//签订代理 实现代理中的方法
[self presentViewController:one animated:YES completion:^{
//self.view.backgroundColor = [UIColor blueColor];用系统方法进行回调
}];
}
//页面B的回调方法拿到页面A里面进行实现
-(void)changeBgColor:(UIColor*)color{
self.view.backgroundColor = color;
}