【问题标题】:UITableViewCell is not receiving the cell object at specified index pathUITableViewCell 没有接收到指定索引路径的单元格对象
【发布时间】:2012-08-29 22:01:00
【问题描述】:

我通过指定 indexPath 手动创建 tableViewCell(自定义)。由于某种原因,有时单元格会接收到单元格对象,有时它不会包含对象。我知道在指定的 indexPath 处存在一个单元格,但更多的原因是代码有时无法从中获取对象。有什么想法吗?

-(BOOL)checkRequiredValues {

    NSIndexPath *cellIndexPath;
    CheckoutCell *cell;

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

}

【问题讨论】:

    标签: objective-c ios ipad uitableview


    【解决方案1】:

    如果单元格不可见,UITableView 上的 cellForRowAtIndexPath: 将返回 nil

    表示表格单元格的对象,如果单元格不可见或 indexPath 超出范围,则为 nil

    如果您想一直获取一个单元格,请在您的数据源上调用相同的方法:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      • 2011-02-02
      • 1970-01-01
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      • 2017-08-05
      相关资源
      最近更新 更多