Assigning retained object to weak property object will be released after assignment

简介:

在ARC中,如果添加了weak的属性。初始化了相关的object然后给这个属性赋值的时候就会看到Xcode给出这个提示。

这个时候可以这么处理:在别的地方已经retain这个object的引用。

复制代码
@property (nonatomic, weak) KGModalContainerView *containerView;
...
-(void)viewDidLoad {
    [super viewDidLoad];
    KGModalContainerView *myContainerView = [[KGModalContainerView alloc] initWithFrame:containerViewRect]; // This is a strong reference to that view
    [self.view addSubview:myContainerView]; //Here self.view retains myContainerView
    self.containerView = myContainerView; // Now self.containerView has weak reference to that view, but if your self.view removes this view, self.containerView will automatically go to nil.

 // In the end ARC will release myContainerView, but it's retained by self.view and weak referenced by self.containerView
}
复制代码

在这个例子中,先初始化了ContainerView。然后把这个View放到self.view的子View中,也就是retain了ContainerView。

然后再把ContainerView赋值给weak属性里。

各位都知道了吧。

欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 572064792 | Nodejs:329118122 做人要厚道,转载请注明出处!













本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sunshine-anycall/p/3436659.html ,如需转载请自行联系原作者


相关文章
成功解决AttributeError: ‘PathCollection‘ object has no property ‘n_levels‘
成功解决AttributeError: ‘PathCollection‘ object has no property ‘n_levels‘
|
数据可视化 Python
AttributeError: ‘Rectangle‘ object has no property ‘normed‘ 解决方法 matplotlib绘图
AttributeError: ‘Rectangle‘ object has no property ‘normed‘
921 0
AttributeError: ‘Rectangle‘ object has no property ‘normed‘ 解决方法 matplotlib绘图
|
Python
Python 修改tuple元组提示:TypeError: ‘tuple‘ object does not support item assignment. 问题原因
Python 修改tuple元组提示:TypeError: ‘tuple‘ object does not support item assignment. 问题原因
1413 0
成功解决AttributeError: ‘PathCollection‘ object has no property ‘n_levels‘ daiding
成功解决AttributeError: ‘PathCollection‘ object has no property ‘n_levels‘ daiding
成功解决AttributeError: ‘PathCollection‘ object has no property ‘n_levels‘
成功解决AttributeError: ‘PathCollection‘ object has no property ‘n_levels‘
成功解决random.py"之TypeError: 'range' object does not support item assignment
成功解决random.py"之TypeError: 'range' object does not support item assignment
成功解决random.py"之TypeError: 'range' object does not support item assignment 解决问题
成功解决random.py"之TypeError: 'range' object does not support item assignment
成功解决random.py"之TypeError: 'range' object does not support item assignment 解决问题
成功解决random.py"之TypeError: 'range' object does not support item assignment 解决问题
|
Web App开发 Java Apache
EL1008E: Property or field 'timestamp' cannot be found on object of type 'java.util.HashMap' - maybe
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/81703902 完整的异常信息: org.
8776 0

热门文章

最新文章