你的位置:首页 > 软件开发 > 操作系统 > IOS 杂笔-14(被人遗忘的owner)

IOS 杂笔-14(被人遗忘的owner)

发布时间:2016-03-26 11:00:14
*owner在开发中现在已经很少用了 有兴趣的童鞋可以看看*我们遇到owner通常是在类似[[[NSBundle mainBundle] loadNibNamed:@"Food" owner:nil options:nil]lastObject ]中遇到的。我 ...

IOS 杂笔-14(被人遗忘的owner)

*owner在开发中现在已经很少用了 有兴趣的童鞋可以看看*

我们遇到owner通常是在类似

[[[NSBundle mainBundle] loadNibNamed:@"Food" owner:nil options:nil]lastObject ]中遇到的。

我们一般的做法是直接把owner设置为self(通常是咋自定义cell时)。

但是在定义其他控件时我们就需要想一想为什么,或者还有什么需要注意的。

下面我开始对owner进行介绍。

先仔细观察下面gif的内容:

IOS 杂笔-14(被人遗忘的owner)

不难发现,我在努力的拖空间就是不成功,这是为什么呢???

接下来看下面的gif

IOS 杂笔-14(被人遗忘的owner)

我们拖控件成功(注意*这里就是为什么现在用owenr的越来越少,因为耦合行套高,不适于提高编码效率)

简单的应用:

IOS 杂笔-14(被人遗忘的owner)

//// ViewController.m// CX 被人遗忘的owner//// Created by ma c on 16/3/26.// Copyright © 2016年 xubaoaichiyu. All rights reserved.//#import "ViewController.h"@interface ViewController ()@property (weak, nonatomic) IBOutlet UIButton *foodOne;@property (weak, nonatomic) IBOutlet UIButton *foodTwo;@end@implementation ViewController- (IBAction)foodOneAction:(id)sender {  NSLog(@"foodOne");  }- (IBAction)foodTwoAction:(id)sender {  NSLog(@"foodTwo");}- (void)viewDidLoad {  [super viewDidLoad];  self.view = [[[NSBundle mainBundle] loadNibNamed:@"Food" owner:self options:nil]lastObject ];}@end

原标题:IOS 杂笔-14(被人遗忘的owner)

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。