Assigning retained object to weak property object
2016-07-28 00:00
851 查看
Assigning retained object to weak property object will be released after assignment
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属性里。
各位都知道了吧。
相关文章推荐
- java中object文档
- [GIF] Shape Objects in GIF Loop Coder
- Volley的三种基本用法StringRequest的Get和post用法以及JsonObjectRequest
- 【Basic computer】-----Java Spring :Injection Objects (注入对象篇)
- Objective-C之run loop详解
- 【转】第7篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:全自动注册与反射方法分析
- 【转】第6篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:自动注册JS脚本+自动反射方法分析
- 【转】第5篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:自动注册JS脚本+委托回调方法分析
- 【转】第4篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:委托回调方法分析
- 【转】3篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:官方原生方法分析
- Objective-C Runtime Reference
- NSAttributedString——为Label设置富文本
- PyGobject(三十)布局容器之StackSidebar
- PyGobject(二十九)布局容器之SearchBar
- Objects聚合分组,统计结果个数(Count)
- PyGobject(二十八)布局容器之Revealer
- ObjC的Block中使用weakSelf/strongSelf @weakify/@strongify
- LocNet: Improving Localization Accuracy for Object Detection
- Python <built-in method items of dict object at 0x0000000002B6C8C8> 问题解决
- PyGobject(二十五)布局容器之Overlay