Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When registering a UITableViewCell for reuse, which init method on that cell gets called? [duplicate]

I'm trying to use a custom subclass of UITableViewCell with the style set to UITableViewCellStyleSubtitle and use it with registerClass:forCellReuseIdentifier:. However, I'm not sure how to do this.

My thinking was to override the init method and call

self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:myReuseIdentifier];

within it. However, I can't figure out which init method gets called (or if this is even the right way to do this.)

I've tried to intercept all of the following init methods, but none of them seem to be the correct one when dequeueing a cell:

  • init
  • initWithCoder
  • initWithFrame

I've confirmed that dequeueReusableCellWithIdentifier:forIndexPath: is returning a cell of the correct type so I know it's being created. I just don't know which init method is being called so I can't set the default style.

like image 875
Mark A. Donohoe Avatar asked Mar 06 '13 04:03

Mark A. Donohoe


1 Answers

I believe it calls initWithStyle:reuseIdentifier: for the table cell init.

From the apple docs

dequeueReusableCellWithIdentifier:

If you registered a class for the specified identifier and a new cell must be created, this method initializes the cell by calling its initWithStyle:reuseIdentifier: method. For nib-based cells, this method loads the cell object from the provided nib file. If an existing cell was available for reuse, this method calls the cell’s prepareForReuse method instead.

J

like image 97
John Avatar answered Oct 11 '22 17:10

John