覆盖自定义的UITableViewCell

我有一个自定义的UITableViewCell ,我这样使用:

 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; } } } 

作品完美无瑕。 但是,我想在创build单元格时对单元格进行一些自定义的操作。 通常我会覆盖像initWithFrame ,但它没有在这里使用。 我应该重写什么方法来自定义初始化?

正确的方法是重写UITableViewCell的awakeFromNib。

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

请参阅参考了解更多详情

从nib中取消存档的对象将发送-initWithCoder:消息。 这是你的重点。