Why is the nib-based custom cell table init method not called

I have a nib-based table cell that I created in the interface builder. I set the table view cell class to FooTableViewCell , which extends from UITableViewCell .

In FooTableViewCell I override the init method as follows:

 -(id)init{ if ((self = [super init])){ // My init code here } return self; } 

Now I was expecting my call to be called when it is created. However, the table view is displayed, but the method is never called.

I could get around this, but I would like to fully understand it, and it is not clear to me how an object can live without calling the init method.

+7
source share
2 answers

When unlocking, initialization is a little different.

Instead of -(id)init , called -(id)initWithCoder:(NSCoder*)aDecoder , is called. At this point, the outputs are not connected, if you need access to the outputs, you can override -(void)awakeFromNib , which is called after the object has been connected.

+19
source

When the object is loaded from the nib file, its -awakeFromNib method is called - you can enter your initialization code here:

 - (void)awakeFromNib{ // Init code } 
+6
source

All Articles