【问题标题】:UITableViewController reloadData cellForRowAtIndexPath not being calledUITableViewController reloadData cellForRowAtIndexPath 未被调用
【发布时间】:2015-02-25 17:42:58
【问题描述】:

从其他 viewcontoller 调用 loadData 方法,例如:

TestTVC *testTVC = [[TestTVC alloc] init];
[testTVC loadData];

我把NSLog(@"testTVC Array section:%lu has %lu rows ")放在numberOfRowsInSection中,它返回结果。

但是在 cellForRowAtIndexPath 部分,NSLog(@"cellForRowAtIndexPath") 从未以某种方式打印。

我确信我的委托和数据源设置正确。因为它在[self loadData]时有效

我也尝试在主线程中运行它,它不起作用。

有人知道吗?谢谢。

更新:我使用[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone]; 而不是[self.tableView reloaddata],它可以工作,但它没有重新加载表格单元格中的 UIImages。

NSLog(@"change cell image to testTVCImg1");
[testTVCCell.selectImgView setImage:[UIImage imageNamed:@"testTVCImg1"]];

打印了 NSLog 调试消息,但图像没有改变。

【问题讨论】:

  • 您对loadData 的实现是什么? numberOfRowsInSection 的结果是什么?
  • 插入 testTVC.delegate = self(或 testTVC);和 testTVC.datasource = self(或 testTVC);在 loadData 方法前面。

标签: ios objective-c uitableview


【解决方案1】:

cellForRowAtIndexPath 在单元格可见时被调用。

当你这样做时

TestTVC *testTVC = [[TestTVC alloc] init];
[testTVC loadData];

testTVC 不在视图层次结构中,也不在它的 tableview 中。所以cellForRowAtIndexPath不会被调用。

【讨论】:

  • 您的更新与上一个问题不再相关,应该是一个新问题。这样,您就可以在不损坏前一个问题的情况下为这个新问题添加更多细节。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多