常见的使用场景
1.A控制器push到B控制器, Bpop时需要通知或者传值传值给A控制器
2.A控制器使用B,C等自定义视图,B/C中的交互事件需要通知或者传值给A控制器
3....
使用方法
Test.h文件
@property (nonatomic, copy) void(^test1)(void); //不传参数
@property (nonatomic, copy) void(^test2)(NSString *); //传递1个参数
@property (nonatomic, copy) void(^test3)(NSString *, NSString *); //传递2个参数
@property (nonatomic, copy) NSString *(^test4)(NSString *); //需要返回值,并且传递1个参数
Test.m文件
//string为传给A的数据
self.test1();
self.test2(tring);
self.test3(string, string);
NSString *string = self.test4(string);
NSLog(@"返回值为:%@", string);
//A控制器
Test *test = [[Test alloc] init];
//self 用weak修饰
__weak typeof (self)weakSelf = self;
test.test1 = ^() {
};
test.test2 = ^(NSString *string) {
};
test.test3 = ^(NSString *string1, NSString *string2) {
};
test.test4 = ^NSString *(NSString *string) {
NSLog(@"接到传过来的%@", string);
return @"传给Test";
};