1.传值界面(SendValue):
1.1 SendValue.h文件:
// 定义Block,设置传递的参数 typedef void(^ReturnButtonClick)(UIButton *Button);
// Block属性 @property (nonatomic, copy)ReturnButtonClick returnButtonClick;
// Block回调方法 - (void)returnButtonClick:(ReturnButtonClick)block;
1.2 SendValue.m文件:
- (void)returnButtonClick:(ReturnButtonClick)block { if (block) { self.returnButtonClick = block; } }
// 须要传值的位置 - (void)clickButton:(UIButton *)button { if (self.returnButtonClick) { self.returnButtonClick(button); } }
2.接收界面(ReceiveValue):
在须要接收参数处理的地方回调Block:
SendValue *sendValue = [[SendValue alloc] init]; __weak typeof(self) weakSelf = self; // 避免循环强引用 [sendValue returnButtonClick:^(UIButton *button) { // Block回调处理 weakSelf.backgroundColor = button.backgroundColor; }];