zoukankan      html  css  js  c++  java
  • 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属性里。

    各位都知道了吧。

  • 相关阅读:
    json dump dumps load loads
    python tip: 格式化 深浅copy sorted
    转载整理
    python 计算器练习
    实验5 OSPF虚连接和验证配置
    实验4 OSPF的特殊区域STUB和NSSA
    实验3ospf路由聚合
    实验2 OSPF基本配置
    实验1静态ECMP的浮动静态路由配置
    补充实验6:tftp
  • 原文地址:https://www.cnblogs.com/sunshine-anycall/p/3436659.html
Copyright © 2011-2022 走看看