自定义UITableViewCell的覆盖

use*_*895 11 iphone ios

我有一个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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

工作完美无瑕.但是,我想在创建时为单元格做一些自定义的事情.通常我会覆盖类似的东西initWithFrame,但它没有在这里使用.我应该覆盖哪种方法来自定义初始化?

Vic*_*tor 19

正确的方法是为UITableViewCell重写awakeFromNib.

- (void)awakeFromNib
{
    [super awakeFromNib];
    // Do something
}
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅参考