Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

override for custom UITableViewCell

Tags:

ios

iphone

I have a custom UITableViewCell that I use like this:

AppTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"AppTableCell" owner:self options:nil];  
    for(id currentObject in topLevelObjects) {
        if([currentObject isKindOfClass:[AppTableCell class]]) {
            cell = (AppTableCell *)currentObject;
            break;
        }
    }
}

Works flawlessly. But, I would like to do some custom things to the cell when they get created. Normally I would override something like initWithFrame, but its not being used here. What method should I override to customize initialization?

like image 878
user1007895 Avatar asked Dec 06 '11 21:12

user1007895


2 Answers

The right way is to override awakeFromNib for UITableViewCell.

- (void)awakeFromNib
{
    [super awakeFromNib];
    // Do something
}

See references for more details.

like image 65
Victor Avatar answered Nov 15 '22 07:11

Victor


Objects that are unarchived from a nib are sent the -initWithCoder: message. That's your override point.

like image 29
Mark Adams Avatar answered Nov 15 '22 07:11

Mark Adams