Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prototype cells with custom class does not fire init?

I am pretty new to objective-c and have a question regarding prototype cells.

I have a tableview with custom cells, and it works nicely.

Now I have also in my custom cell class overridden -(id)init and -(id)initWithStyle: reuseIdentifier:

If I do a class check on the cell, it is clearly of my custom class, but neither init method is ever called.

So it creates them for me, but somehow avoids firing -(id)init which seems wierd to me.

I guess I could init them on my own but it seems really wierd that they can exist without having been created?

Thank you!

like image 225
Ostmeistro Avatar asked Aug 30 '26 21:08

Ostmeistro


1 Answers

If its a prototype cell from a story board. - (id)initWithCoder: gets called. So you need to override:

- (id)initWithCoder:(NSCoder *)coder
{
  self = [super initWithCoder:coder];
  if (self) {
       //custom stuff here
  }

  return self;
}

This is true for anything awakened from a storyboard.

like image 75
theVurt Avatar answered Sep 02 '26 10:09

theVurt