在块中更改实例变量 [英] Changing an instance variable in a block
本文介绍了在块中更改实例变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对于如何在块内更改实例变量感到非常困惑.
I am quite confused about how to change an instance variable inside of a block.
接口文件(.h):
@interface TPFavoritesViewController : UIViewController {
bool refreshing;
}
实现:
__weak TPFavoritesViewController *temp_self = self;
refreshing = NO;
[myTableView addPullToRefreshWithActionHandler:^{
refreshing = YES;
[temp_self refresh];
}];
您可能会猜到,当我尝试更改该块内部的刷新ivar时,会收到一个保留周期警告.我该怎么做而不会出错?
As you might guess, I get a retain cycle warning when I try to change the refreshing ivar inside of the block. How would I do this without getting an error?
推荐答案
您对refreshing
的赋值是对self
的隐式引用,它的简写为:
Your assignment to refreshing
is an implicit reference to self
, it is shorthand for:
self->refreshing = YES;
因此出现循环警告.更改为:
hence the cycle warning. Change it to:
temp_self->refreshing = YES;
这篇关于在块中更改实例变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文