ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 低调看直播体育app软件下载 >> IOS开发 >> IBOutlet对象应该使用strong还是weak修饰

IBOutlet对象应该使用strong还是weak修饰(1/2)

来源:网络整理     时间:2016-09-02     关键词:

本篇文章主要介绍了" IBOutlet对象应该使用strong还是weak修饰",主要涉及到方面的内容,对于IOS开发感兴趣的同学可以参考一下: ARC情况下,通常应该使用strong修饰,除非为了避免循环引用的情况。特别是在iOS6之后更应如此,使用weak修饰除了避免循环引用没有其他益处。And th...

ARC情况下,通常应该使用strong修饰,除非为了避免循环引用的情况。特别是在iOS6之后更应如此,使用weak修饰除了避免循环引用没有其他益处。

And the last option I want to point out is the storage type, which can either be strong or weak. In general you should make your outlet strong, especially if you are connecting an outlet to a subview or to a constraint that's not always going to be retained by the view hierarchy. The only time you really need to make an outlet weak is if you have a custom view that references something back up the view hierarchy and in general that's not recommended.

From a practical perspective, in iOS and OS X outlets should be defined as declared properties. Outlets should generally be weak, except for those from File’s Owner to top-level objects in a nib file (or, in iOS, a storyboard scene) which should be strong. Outlets that you create will therefore typically be weak by default, because:

  • Outlets that you create to, for example, subviews of a view controller’s view or a window controller’s window, are arbitrary references between objects that do not imply ownership.

  • The strong outlets are frequently specified by framework classes (for example, UIViewController’s view outlet, or NSWindowController’s window outlet).

    @property (weak) IBOutlet MyView *viewContainerSubview;
    @property (strong) IBOutlet MyOtherClass *topLevelObject;

While the documentation recommends using weak on properties for subviews, since iOS 6 it seems to be fine to use strong (the default ownership qualifier) instead. That's caused by the change in UIViewController that views are not unloaded anymore.

相关图片

相关文章