`

IBoutlet weak strong

阅读更多
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 should therefore typically be weak, because:

Outlets that you create to subviews of a view controller’s view or a window controller’s window, for example, 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;

 当你的IBoutlet是 nib或storyboard的所拥有的view或window时,要声明为strong,其他情况应该声明为weak,因为声明为strong的应该是nib或storyboard所拥有的对象,而我们一般声明的IBoutlet都是某个view或window的subview,所以要声明为weak

Outlets should be changed to strong when the outlet should be considered to own the referenced object:

As indicated previously, this is often the case with File’s Owner—top level objects in a nib file are frequently considered to be owned by the File’s Owner.
You may in some situations need an object from a nib file to exist outside of its original container. For example, you might have an outlet for a view that can be temporarily removed from its initial view hierarchy and must therefore be maintained independently.

 当你的某个IBoutlet要经常在他的原拥有者之外存在,经常要变动他的所有者,比如要经常从一个view移到另一个view,这时需要将其声明为strong

官方文档

分享到:
评论

相关推荐

    05-图片浏览器.zip

    @property (weak, nonatomic) IBOutlet UILabel *indexLabel; // 图像数据 @property (nonatomic, strong) NSArray *imageArray; // 图像控件 @property (weak, nonatomic) IBOutlet UIImageView *imageView; // ...

    iOS 5.0 ARC开发详细解读

    最全面的ARC解读,手把手教会你。文档从基础到高级,从IBOutlet、Property、delloc开始讲解,重点讲解了weak、strong等的用法

    iOS实现一个意见反馈类型的输入栏

    前言 本文主要给大家介绍了关于利用iOS如何实现一个意见反馈类型的输入栏,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。 要做个意见反馈,...@property (weak, nonatomic) IBOutlet UITe

    IOS 开发之查看大图的实现代码

    IOS 开发之查看大图的实现代码 本项目是取自传智播客的教学项目,加入笔者的修改和润饰。 1. 项目名称:查看大图 2. 项目截图展示 3. 项目功能 左右滑动查看图片 ...@property (weak, nonatomic) IBOutlet U

    iOS图片界面翻页切换效果

    @property (weak, nonatomic) IBOutlet UIImageView *backgroundView; @property (strong,nonatomic) NSArray *array; @end @implementation ViewController -(NSArray *)array { if (_array == nil) { UIImage...

    超精准的iOS计步器实现代码

    本文实例为大家分享了iOS计步器实现代码,供大家参考,具体内容如下 ...@property (weak, nonatomic) IBOutlet UILabel *stepLabel; @end @implementation ViewController - (void)viewDidLoad { [super

    iOS使用UIScorllView实现两指缩放功能

    两指缩放功能不仅可以用UIPinchGestureRecognizer手势来实现,...@property (weak, nonatomic) IBOutlet UIScrollView *scrollView; @property (strong, nonatomic) UIImageView *imageView; @end @implementation Vie

    RTDataSourceAdapter:RTDataSourceAdapter是一个简化UITableView控件工作的库

    @property ( weak , nonatomic ) IBOutlet UITableView *myTable; @property ( strong , nonatomic ) RTDataSourceAdapter *adapter; .... @end 创建RTDataSourceAdapter self.adapter = [[RTDataSourceAdapter ...

    IOS实现基于CMPedometer的计步器

    CMStepCount类在IOS8已经不推荐使用了,IOS8推荐使用CMPedometer类来处理用户健康和运动信息...@property (weak, nonatomic) IBOutlet UILabel *stepLabel; @property(nonatomic,strong) CMPedometer *stepter; @propert

    JTBorderDotAnimation:一个简单的动画,圆点围绕 iOS 的 UIView

    # import " JTBorderDotAnimation.h "@interface ViewController : UIViewController@property ( weak , nonatomic ) IBOutlet UIView *animatedView;@property ( strong , nonatomic ) JTBorderDotAnimation *...

Global site tag (gtag.js) - Google Analytics