IOS 雜筆-14(被人遺忘的owner),ios-14

來源:互聯網
上載者:User

IOS 雜筆-14(被人遺忘的owner),ios-14

*owner在開發中現在已經很少用了 有興趣的童鞋可以看看*

我們遇到owner通常是在類似

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

我們一般的做法是直接把owner設定為self(通常是咋自訂cell時)。

但是在定義其他控制項時我們就需要想一想為什麼,或者還有什麼需要注意的。

下面我開始對owner進行介紹。

先仔細觀察下面gif的內容:

不難發現,我在努力的拖空間就是不成功,這是為什麼呢???

接下來看下面的gif

我們拖控制項成功(注意*這裡就是為什麼現在用owenr的越來越少,因為耦合行套高,不適於提高編碼效率)

簡單的應用:

////  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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.