2011-05-10 83 views
0

遵循NIB(动态选项)中的自定义单元格的文档,我有这种方法。 (视图本身不是一个UITableViewController,但它的正确挂接。)故障子类化UITableViewCell(2警告)

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"ReusableCell"; 

    UITableViewCell *cell = (LoadGameCell *) 
        [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[NSBundle mainBundle] 
        loadNibNamed:@"LoadGameCell" owner:self options:nil]; 
     cell = loadGameCell; 
     self.loadGameCell = nil; 
    } 

    /* 
    cell setup 
    */ 

    return cell; 
} 

if语句中的第一行是我遇到的麻烦位。

Incompatible pointer types assigning to 'UITableViewCell *' from 'NSArray *' 

Incompatible Objective-C types assigning 'struct NSArray *', 
           expected 'struct UITableViewCell *' 

没有错误/崩溃与这些警告运行应用程序,但我宁愿不忽略/压制它们。它会在以后更多的伤害。

如果它不是上述警告的直接结果,还有另一个问题。我无法获得观看的方法,只有标签。 (也就是说,我可以自定义一个标签,但不是它旁边坐着的图像视图。)

回答

0

正如文档将告诉你的,loadNibNamed:owner:options:返回一个数组。要访问NIB中的单元格(假定它是NIB中唯一的根级对象),请致电objectAtIndex:0loadNibNamed:owner:options的结果。

+0

对于这种简单的bug,我毫无用处......它们很微妙,所以我完全想念它们。谢谢。 – Thromordyn 2011-05-10 14:12:08