twinlakes
twinlakes

Reputation: 10238

What init method is called when creating a UITextField in storyboard

The question: I subclassed a UITextField as "UISelectField" so that I could override the delegate. I then created a UITextField in storyboard and changed its class to UISelectField in the Identity inspector. However, the default init method provided by Xcode, "initWithFrame", does not get called. What init method gets called when creating a UITextField with this approach?

The reason: Right now, I set the delegate in my view controller's init: [self.textField setDelegate:self.textField];. I would like to remove this and replace it with [self setDelegate:self]; in whatever init method gets called. Please tell me if there is a more elegant approach.

Upvotes: 1

Views: 2280

Answers (2)

pableiros
pableiros

Reputation: 16032

On Swift 3:

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

    // Custom Implementation
}

Upvotes: 0

acorc
acorc

Reputation: 360

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        // Custom Implementation
    }
    return self;
}

Upvotes: 4

Related Questions