处理Block中的self问题(Capturing 'self' strongly in this block is likely to lead to a retain cycle)
警告: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];
});
});
};
处理Block中的self问题(Capturing 'self' strongly in this block is likely to lead to a retain cycle)的更多相关文章
- 在block函数中规避错误信息 "capturing self strongly in this block is likely to lead to a retain cycle”
以形如 _fontValueChangedBlock = ^(){ [self.fontSmallButton addTarget:self action:@selector(btnFontSmall ...
- capturing self strongly in this block is likely to lead to a retain cycle
一个用Block实例变量语法,当有一个参考的实例变量,常引起retain cycle. capturing self strongly in this block is likely to lead ...
- xcode arc 下使用 block警告 Capturing [an object] strongly in this block is likely to lead to a retain cycle” in ARC-enabled code
xcode arc 下使用 block警告 Capturing [an object] strongly in this block is likely to lead to a retain cyc ...
- 决绝Capturing 'demo' strongly in this block is likely to lead to a retain cycle
- (IBAction)onTest:(id)sender { BlockDemo *demo = [[BlockDemo alloc]init]; __weak typeof(BlockDemo) ...
- block中self关键字的使用-防止self 被retain一次
在代码块中使用对象的成员时(成员变量是属性strong,MRC估计是retain时效果一样,使用方法时也一样): 警告: capturing self strongly in this block i ...
- [ios2]警告:Block的Retain Cycle的解决方法 【转】
<span style="background-color: rgb(248, 248, 248); font-family: 'PT Sans', Geogia, Baskervil ...
- Block的Retain Cycle的解决方法
一个使用Block语法的实例变量,在引用另一个实例变量的时候,经常会引起retain cycle.这个问题在使ASIHTTPRequest的block语法的时候会时不时的碰到.这个问题困扰了我这个小白 ...
- iOS 中block中使用了外部变量的分析
例子1: ; void (^blk)(void) = ^(){ printf("in block %d[%p]\n", val, &val); //in block 10[ ...
- block中如何避免循环引用
使用 weak–strong dance 技术 block 可以直接引用 self,但是要非常小心地在 block 中引用 self.因为在 block 引用 self,可能会导致循环引用.如下例所示 ...
随机推荐
- HDU1102--Constructing Roads(最小生成树)
Problem Description There are N villages, which are numbered from 1 to N, and you should build some ...
- MFC设置窗体大小SetWindowPos
SetWindowPos(NULL,0,0,200,300,SWP_NOMOVE); 表示不考虑(0,0),仅仅将大小改为200x300,位置不变 SetWindowPos(NULL,0,0,2 ...
- 动态规划3-------poj1050
首先还是对题目的意思进行说明,给出一个矩阵的数,然后求出一个子矩阵这个子矩阵包含的数的和是最大的. 首先对于题目进行转化,利用一个数组add进行存放临时数据,第一行存放原来数据的第一行,第二行存放 ...
- getWriter() has already been called for this response 的解决办法
getWriter() has already been called for this response response已经被其他对象调用了,导致无法继续使用如下 类似的方法 PrintWrite ...
- sql语句删除由于无主键导致完全重复的数据方法
sql语句删除由于无主键导致完全重复的数据方法 select distinct * into #Tmp from t_column drop table t_column select * into ...
- 关于127.0.0.1与localhost
127.0.0.1是不会经过防火墙的,而localhost是要通过防火墙取地址的.
- FusionCharts生成报表应用
1.需要组装要展示的数据,至于如何怎样去设计数据模型,看你要展示的图形和需要的数据就行了.来个简单的. 实体类,只有两个属性,也可以使用Bean里面的实体类,无所谓了. package com.gol ...
- 关于数据结构的10个面试题(c语言实现)
关于数据结构的10个面试题(c语言实现) 2010-04-21 22:17 5702人阅读 评论(0) 收藏 举报 数据结构面试c语言bttree 1. 输入一个链表的头结点,从尾到头 ...
- (转)Hadoop的InputFormats和OutputFormats
Data Mining Hadoop的InputFormats和OutputFormats InputFormat InputFormat类用来产生InputSplit,并把它切分成record. p ...
- UML关系总结
用例图: 1.扩展关系:如果已有一个用例,在这个用例的基础(该用例是完整的)上加入新的动作形成了另一个用例,即后者是通过继承前者的属性并加入新的内容而来的,则前者通常称为通用化用例,后者常为扩展用例. ...