假设有一个类 名字叫做Puzzled继承UIViewController
声明了个属性 @property (nonatomic, strong) UIButton *btn;
跟声明了属性 @property (nonatomic, weak) UIButton *btn;
在- (void)viewDidLoad方法中调用 {
UIButton *btn = [[UIButton alloc]init];
self.btn = btn
}的区别是什么
怪我咯2017-04-17 16:51:09
Since the generated button has no reference elsewhere, the property of the weak attribute will be lost after you assign the value.
大家讲道理2017-04-17 16:51:09
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,