2012-08-29 16 views
2

我手动创建一个tableViewCell(这是自定义的),方法是指定一个indexPath。出于某种原因,有时单元格会接收单元对象,有时它不包含对象。我知道一个单元格存在于指定的indexPath处,但更多的原因是代码有时无法从中获取对象。有任何想法吗?UITableViewCell未在指定的索引路径上接收单元对象

-(BOOL)checkRequiredValues { 

    NSIndexPath *cellIndexPath; 
    CheckoutCell *cell; 

    cellIndexPath = [NSIndexPath indexPathForRow:1 inSection:0]; 
    cell = (CheckoutCell *)[self.tableView cellForRowAtIndexPath:cellIndexPath]; 

} 

回答

3

cellForRowAtIndexPath:UITableView返回nil如果小区是不可见的:

表示表或nil的小区,如果小区是不可见的或indexPath超出范围的对象。

如果你想获得一个小区的时候,调用相同的方法将数据源:

cell = (CheckoutCell *)[self.tableView.dataSource 
    tableView:self.tableView 
    cellForRowAtIndexPath:cellIndexPath 
]; 
相关问题