【问题标题】:What init method is called when creating a UITextField in storyboard在情节提要中创建 UITextField 时调用什么 init 方法
【发布时间】:2013-07-19 00:10:11
【问题描述】:

问题: 我将 UITextField 子类化为“UISelectField”,以便我可以覆盖委托。然后,我在情节提要中创建了一个 UITextField,并在身份检查器中将其类更改为 UISelectField。但是,Xcode 提供的默认初始化方法“initWithFrame”不会被调用。使用这种方法创建 UITextField 时会调用什么 init 方法?

原因: 现在,我在视图控制器的 init 中设置了委托:[self.textField setDelegate:self.textField];。我想在调用任何 init 方法时删除它并用[self setDelegate:self]; 替换它。请告诉我是否有更优雅的方法。

【问题讨论】:

    标签: ios storyboard uitextfield uitextfielddelegate


    【解决方案1】:
    - (id)initWithCoder:(NSCoder *)aDecoder {
        self = [super initWithCoder:aDecoder];
        if (self) {
            // Custom Implementation
        }
        return self;
    }
    

    【讨论】:

      【解决方案2】:

      在 Swift 3 上:

      required init?(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)
      
          // Custom Implementation
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-05-09
        • 1970-01-01
        • 2019-06-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-26
        • 1970-01-01
        相关资源
        最近更新 更多