警告:ARC Retain Cycle
Capturing 'self' strongly in this block is likely to lead to a retain cycle
代码:
self.refreshHeader.beginRefreshingBlock=^(){
// 后台执行:
dispatch_async(dispatch_get_global_queue(0, 0), ^{
sleep(2);
dispatch_async(dispatch_get_main_queue(), ^{
// 主线程刷新视图
weakSelf.total=20;
[self.mainTableView reloadData];
[self.refreshHeader endRefreshing];
});
});
};
针对这个问题,解决很简单,将self弱化即可。修改后代码如下:
__weak MainViewController * weakSelf = self;
self.refreshHeader.beginRefreshingBlock=^(){
// 后台执行:
dispatch_async(dispatch_get_global_queue(0, 0), ^{
sleep(2);
dispatch_async(dispatch_get_main_queue(), ^{
// 主线程刷新视图
weakSelf.total=20;
[weakSelf.mainTableView reloadData];
[weakSelf.refreshHeader endRefreshing];
});
});
};