iOS 一个类中申明一个UIButton* butto 属性用strong 和用属性weak区别
天蓬老师
天蓬老师 2017-04-17 16:49:09
0
2
649

假设有一个类 名字叫做Puzzled继承UIViewController
声明了个属性 @property (nonatomic, strong) UIButton *btn;

跟声明了属性 @property (nonatomic, weak) UIButton *btn;
在- (void)viewDidLoad方法中调用 {
UIButton *btn = [[UIButton alloc]init];
self.btn = btn
}的区别是什么

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
刘奇

Since the generated button has no reference elsewhere, the property of the weak attribute will be lost after you assign the value.

大家讲道理

If there are other objects referencing it, use weak, otherwise use strong

If no object refers to it and it is created out of scope, it will be removed

Also, when dragging objects from xib or storyboard, then use weak at this time,

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template