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


    *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
    复制代码
  • 相关阅读:
    CodeForces 659F Polycarp and Hay
    CodeForces 713C Sonya and Problem Wihtout a Legend
    CodeForces 712D Memory and Scores
    CodeForces 689E Mike and Geometry Problem
    CodeForces 675D Tree Construction
    CodeForces 671A Recycling Bottles
    CodeForces 667C Reberland Linguistics
    CodeForces 672D Robin Hood
    CodeForces 675E Trains and Statistic
    CodeForces 676D Theseus and labyrinth
  • 原文地址:https://www.cnblogs.com/wuyuxin/p/7045583.html
Copyright © 2020-2023  润新知