您的位置:首页 > 移动开发 > IOS开发

ios block 重复引用

2016-03-22 14:09 417 查看
摘要: 为啥要 _weak typeof(self) weakSelf = self

仅是自己的理解 不保证正确 严谨性

需要 _weak typeof(self) weakSelf = self

例子

@interface GoodsDetailController ()

@property(strong,nonatomic) UILabel *testBlockLabel;
@property(strong,nonatomic) NSString *daCai;

@end

@implementation GoodsDetailController
- (void)viewDidLoad {
self.view.backgroundColor = [UIColor redColor];
self.testBlockLabel = [UILabel newAutoLayoutView];
[self.view addSubview:self.testBlockLabel ]; //这里 对label进行了引用
self.testBlockLabel .text = @"dddddddddddd";
[self.testBlockLabel  autoCenterInSuperview];
__weak typeof(self) weakSelf = self;
// addTapActionWithBlock  (https://github.com/shaojiankui/iOS-Categories) 这里有很多好用的东西
[self.testBlockLabel  addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
self.daCai =@"这里会有警告";
weakSelf.daCai =@"这样就没有问题";
}];
}
- (void)dealloc {
NSLog(@"赵大财");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: