I have custom UiTablleviewCell with some images and labels, and I would like to have rotated label in tableview cell...so I would like to edit initWithStyle method, but it seems like it's never called.
- (id)initWithStyle:(UITableViewCellStyle)stylereuseIdentifier:(NSString*)reuseIdentifier{
NSLog(@"creating cell");
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
}
return self;}
but in my log, I cant see this message. In tableview I have standard cellForRow method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"messagesCell";
TBCellMessagesCell *cell = (TBCellMessagesCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// smt stuff
return cell;
}
so I'm wondering how does tableview initialize tableviewcells, I can think about some workarounds but I would like to have it clean. Thank you.
If the cells come from a storyboard or nib file, then initWithStyle:reuseIdentifier
is not called, initWithCoder:
is called instead.
Here's a typical implementation of an overwritten initWithCoder:
:
-(id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// Do your custom initialization here
}
return self;
}
Will not work if you need to access IBOutlet during custom initialization.
You might also consider the awakeFromNib method if you need to talk with IBOutlet.
Discussion
The nib-loading infrastructure sends an awakeFromNib message to each object recreated from a nib archive, but only after all the objects in the archive have been loaded and initialized. When an object receives an awakeFromNib message, it is guaranteed to have all its outlet and action connections already established.
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