当不使用界面生成器时,我总是强烈引用 UI 元素:
@interface myViewController : UIViewController
@property (nonatomic, strong) UILabel *folderLabel;
然后像这样添加它们:
[self.view addSubview self.folderLabel];
因此,初始化程序是:
-(UILabel *)folderLabel{
if(!_folderLabel) {
_folderLabel = [[UILabel alloc] init];
_folderLabel.text = @"foo";
}
return _folderLabel
}
有人告诉我,由于某种原因,这很糟糕,他们应该总是很弱。
@property (nonatomic, weak) UILabel *folderLabel;
-(UILabel *)folderLabel{
if(!_folderLabel) {
UIlabel *folderLabel = [[UILabel alloc] init];
folderLabel.text = @"foo";
[self.view addSubview:folderLabel];
_folderLabel = folderLabel;
}
return _folderLabel
}
强引用在这里是一件坏事吗?