我有一个UITableViewController管理iPad应用程序中的UITableView对象.表视图与其他对象的相当复杂的星座相关联.当我要求它按如下方式重新加载时,我遇到了问题:
//indexPath is an NSIndexPath with indexes 0 and 0. At the moment, this is the only cell in the table view.
NSArray *array = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];
Run Code Online (Sandbox Code Playgroud)
问题是该行没有重新加载.永远不会回调cellForRowAtIndexPath.
疯狂的是,如果我两次调用reloadRowsAtIndexPaths,第二次调用会触发重新加载:
//indexPath is an NSIndexPath with indexes 0 and 0. At the moment, this is the only cell in the table view.
NSArray *array = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone]; // does not reload
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone]; // does reload
Run Code Online (Sandbox Code Playgroud)
我想知道是否有其他人遇到过这样的错误,如果是这样,原因是什么?
正如Apple Doc所说,
重新加载行会导致表视图向其数据源询问该行的新单元格.
我将UITableView与NSFetchedResultsController结合使用:
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
if (self.tableView.isEditing)
{
[self.tableView setEditing:NO animated:YES];
}
[self.tableView beginUpdates];
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView endUpdates];
[self updateTabItemBadge];
[self.noDataView setHidden:![self isNoData]];
WXINFO(@"controllerDidChangeContent");
}
Run Code Online (Sandbox Code Playgroud)
在上述两个函数之间,我重新加载目标单元格:

case NSFetchedResultsChangeUpdate: {
if (indexPath) {
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
Run Code Online (Sandbox Code Playgroud)

我在Line1563设置了一个断点,检查reloadRowsAtIndexPaths是否已经调用了,但之后- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath没有被调用.
所以,我的手机无法更新.
有人可以告诉我为什么?谢谢.