【发布时间】:2014-08-06 02:04:32
【问题描述】:
我正在使用 ARC 专门为 iOS 5 开发。 IBOutlets 到 UIViews(和子类)应该是 strong 还是 weak?
以下内容:
@property (nonatomic, weak) IBOutlet UIButton *button;
将摆脱所有这些:
- (void)viewDidUnload
{
// ...
self.button = nil;
// ...
}
这样做有什么问题吗?模板使用strong,就像从“Interface Builder”编辑器直接连接到标题时创建的自动生成的属性一样,但为什么呢? UIViewController 已经有一个 strong 引用对其 view 保留其子视图。
【问题讨论】:
-
注意,
IBOutletCollection()不能是weak,否则返回为nil。 -
Xcode 8.2.1 在通过接口生成器创建 IBOutlets 时使用弱。但是这里关于 SO 的许多答案都建议使用 strong。
-
@neoneye 我刚刚尝试使用 xcode 8.3.2 从情节提要拖动到 swift 文件,默认为
strong
标签: ios objective-c cocoa-touch interface-builder automatic-ref-counting