1、 __weak 与__strong 组合
__weak typeof(self) weakself = self;
self.BLOCK= ^{
__strong typeof(weakself) strongself = weakself;
NSLog(@"%@",strongself.name);
};
2、--block与临时变量结合使用
__block OneViewController *vc = self;
self.BLOCK= ^{
NSLog(@"%@",vc.name);
vc=nil;
};
3、把self当作block的参数传递过去
self.BLOCK = ^(OneViewController *vc){
NSLog(@"%@",vc.name);
};
self.BLOCK(self);
网友评论