2011-04-27 56 views
0

我有一个UITableViewCell定义在一个XIB(带插座设置)和自定义类设置为'CustomTableViewCell'。 ?现在我正在寻找子类“CustomTableViewCell”与“SubclassCustomTableViewCell”,但我想使用相同的XIB(而不是需要重新定义我认为这是可能我目前有: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
+ (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定义,其中类

+0

它在子类中定义。我我不知道如何改变呼叫可能返回零应该有所帮助...我确实希望它r修改表格视图单元格... – 2011-04-27 07:14:33

+0

是啊,这不会帮助..但它会返回自定义单元格或零...它不会返回父单元格。我在for循环中添加了'return cell;'。并且请放入所有的类别 – 2011-04-27 08:19:45

+0

但是,XIB文件将父级单元格设置为类。如果这是在孩子身上运行,它永远不会返回任何东西...... – 2011-04-28 16:26:42