I have a UITableViewController subclass with its prototype cells mocked up in the storyboard.
There's a fair amount of code in the cellForRowAtIndexPath
delegate method that sets up the cells. Problem is I don't need most of it if the cell is just being dequeued from the reuse pool, because it's already been done when the cell was dequeued the first time. I can't do it in the storyboard because there are some properties I can only access programmatically.
Does the UITableViewController call an initializer in my UITableViewCell subclass when it takes a prototype cell from the storyboard? I tried (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
but that does not appear to be part of the process.
I probably didn't phrase my question properly but I was looking for here was actually (void)awakeFromNib
.
Gets called once when the cell is dequeued and not on reuse. Allows me to do some setup programmatically that it doesn't make sense to do in the storyboard.
When a UITableView instance calls for dequeueReusableTileWithIdentifier:
, the cell is not reinitialized. Instead, in that call, the UITableViewCell that is dequeued will call -(void)prepareForReuse
. This is because reinitializing the cell is costly, and if we can provide a much simpler method for preparing for its reuse (eh, eh, get it?) it saves a whole lot of CPU work.
Ergo, if you're using custom cells, override UITableViewCell prepareForReuse
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With