shmuelie
shmuelie

Reputation: 1225

initwithstyle:reuseIdentifier: not called

I'm creating my own custom UITableViewCell to use as the backend of a prototype cell. In my class I override the initwithstyle:reuseIdentifier: method to do some custom initialization, but my initializer is not called. I have a break point on the first line inside of it, as well as a break point on dequeueResusableCellWithIdentifier:. The dequeueResusableCellWithIdentifier: method is called, and it returns a initilized cell, but the break point in initwithstyle:reuseIdentifier: is not reached. Any help would be great.

Upvotes: 46

Views: 12240

Answers (3)

Mahesh Aswathanarayana
Mahesh Aswathanarayana

Reputation: 161

If you are using StoryBoarsd then UITableViewContoller won't call initWithStyle replace it with initWithCoder it will works now

Upvotes: 0

carbonr
carbonr

Reputation: 6067

With the storyboard involved, everything changes. This is the method that gets called.

-(id)initWithCoder:(NSCoder *)aDecoder {
    if ( !(self = [super initWithCoder:aDecoder]) ) return nil;

    // Your code goes here!

    return self;
}

Upvotes: 12

jrturton
jrturton

Reputation: 119242

If your cell is being created from a storyboard prototype (which you have declared as the custom class in IB) then it won't be created with initWithStyle... but initWithCoder: instead, like any other object loaded from a nib. If you have any setup code, it should be in there or in awakeFromNib.

Upvotes: 83

Related Questions