XIB支持View with Subclassing

时间:2011-04-27 05:26:44

标签: iphone objective-c cocoa-touch

我在XIB中定义了UITableViewCell(带有出口设置),自定义类设置为'CustomTableViewCell'。我现在想要使用'SubclassCustomTableViewCell'继承'CustomTableViewCell',但是我想使用相同的XIB(而不需要重新定义我的视图。这可能吗?我目前有:

+ (SubclassCustomTableViewCell *)create
{
    // Create undefined cell.
    id cell = nil;

    // Iterate over NIB and find a matching class.
    NSBundle *bundle = [NSBundle mainBundle];
    NSArray *cells = [bundle loadNibNamed:@"CustomTableViewCell" owner:nil options:nil];
    for (cell in cells) if ([cell isKindOfClass:[self class]]) break;

    // Return cell.
    return cell;
}

但我无法想办法让它除了父母以外的任何东西。

1 个答案:

答案 0 :(得分:-1)

+ (SubclassCustomTableViewCell *)create
{
    // Create undefined cell.
    id cell = nil;

    // Iterate over NIB and find a matching class.
    NSBundle *bundle = [NSBundle mainBundle];
    NSArray *cells = [bundle loadNibNamed:@"CustomTableViewCell" owner:nil options:nil];
    for (cell in cells) if ([cell isKindOfClass:[self class]]) return cell; //change this

    // Return cell.
    return nil; //change this
}

你能告诉我+ (SubclassCustomTableViewCell *)create在哪个类中的定义