【问题标题】:Is cellForRowAtIndexPath called when you use a custom cell?使用自定义单元格时是否调用了 cellForRowAtIndexPath?
【发布时间】:2015-10-16 23:53:04
【问题描述】:

我在 tableview 控制器中使用自定义单元格类。

当我在 cellForRowAtIndexPath NSLog(@"method called"): 的 tableviewcontroller 中包含一条语句时,它似乎没有被调用。

当您有自定义单元格时,是否可能不调用此方法?

编辑:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"cell for row at index path called");
    NSDictionary *item= [self.getItems objectAtIndex:indexPath.row];    
    //This sets place in storyboard VC
    IDTVCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Cell"];
    cell.item = item;
    if (cell == nil) {
        cell = [[IDTVCell alloc] initWithStyle:UITableViewCellStyleDefault
                               reuseIdentifier:@"Cell"];
    }
    return cell;
    }

【问题讨论】:

  • 用您的实际cellForRowAtIndexPath 方法更新您的问题。还要确保您的数据源方法返回的行数非零。
  • numberofrowsinsection 方法返回指定的多个,即 return 1 返回 1。但是,似乎没有调用 cellforrowatindexpath。
  • 如果你有非零部分和非零行,那么应该调用cellForRow... 方法。你确认numberOfRowsInSection: 被调用了吗?
  • 是的,它肯定被称为。在viewdidload之前按照控制台中的顺序。我想知道自定义单元格是否对此有影响。
  • 这是UITableViewController 还是UIViewController 加上UITableView?如果是后者,表格视图的框架是否设置正确? self.getItems是如何初始化的?

标签: ios objective-c uitableview


【解决方案1】:

如果没有返回行,则不调用cellForRowAtIndexPath。

-tableView:cellForRowAtIndexPath: is not getting called

这就是我的情况。

如果您在错误的线程和某些其他情况下重新加载表,它也不会返回。

cellForRowAtIndexPath: not called

但是,自定义单元本身不会导致这种情况..

【讨论】:

    【解决方案2】:

    回答您的问题 - 是的。

    cellForRowAtIndexPath: 没有被调用可能有多种原因。这可能是因为delegate / dataSource 未设置或UITableView 框架未设置...等等等等。

    您应该通过更多的在线研究和关闭查看您的代码轻松找到解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多