- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if ([BGSearchParameter defaultSearchParameters].fetchedResults.count==0)
{
PO(@([self.tableView numberOfRowsInSection:0]));
PO(@([self tableView:nil numberOfRowsInSection:0]));
PO(@(indexPath.row));
while (false);
}
这是结果
self.tableView numberOfRowsInSection:0]): 20
@([self tableView:nil numberOfRowsInSection:0]): 0
现在,我不知道是谁叫cellForRowAtIndexPath
。
这是截图
debuggin窗口显示主线程以某种方式调用cellForRowAtIndexPath
。
我通常会通过返回一些从未显示的随机UITableViewCell
来解决此问题。然而,我认为这是一个错误。
除了tableReload之外,还有哪些函数可以调用cellForRowAtIndexPath
以及它为什么不调用
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
第一
似乎我的tableView仍然认为有20行,即使只有0行。
答案 0 :(得分:1)
问题似乎是你的tableview并不令人耳目一新。请在代码中包含此行,以便每次都引用: -
[yourTableView reloadData];
答案 1 :(得分:1)
您可以使用此方法的参数“tableView”来检查是否调用了“UITableView”的正确实例。例如,在委托方法“ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section”中添加以下代码:
if(tableView== youwanttocheckTableView) {
//do what you want to do
}
您还可以检查哪个TableView实例已将其委托设置为此类中的“self”。