Custom Initialization UITableVIewCell

I have a custom UiTablleviewCell with some images and shortcuts, and I would like to have the rotated label in the tableview cell ... so I would like to edit the initWithStyle method, but it seems like it has never been called.

- (id)initWithStyle:(UITableViewCellStyle)stylereuseIdentifier:(NSString*)reuseIdentifier{ NSLog(@"creating cell"); self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { } return self;} 

but in my journal I do not see this message. In tableview, I have a 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 wonder how tableview initializes tableviewcells, I can think of some workarounds, but I would like it to be clean. Thanks.

+7
initialization ios uitableview
source share
2 answers

If the cells exit the storyboard or nib file, then initWithStyle:reuseIdentifier not called, instead, initWithCoder: called.

Here's a typical implementation of a rewritten initWithCoder: ::

 -(id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self) { // Do your custom initialization here } return self; } 

Will not work if you need access to IBOutlet during user initialization.

+14
source share

You can also consider the method

+8
source share

All Articles