Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 410
shmuelie Avatar asked Dec 15 '11 15:12

shmuelie


2 Answers

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.

like image 162
jrturton Avatar answered Sep 22 '22 04:09

jrturton


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; } 
like image 32
carbonr Avatar answered Sep 22 '22 04:09

carbonr