1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Assigning retained object to weak property object will be released after assignment

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

时间:2022-10-21 17:09:25

相关推荐

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 myContainerViewself.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博客园博客,原文链接:/sunshine-anycall/p/3436659.html,如需转载请自行联系原作者

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。