我有一个 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];
问题是该行不会重新加载。永远不会有对 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
我想知道是否有其他人遇到过这样的错误,如果有的话,原因是什么?
reloadRowsAtIndexPaths:...
仅当包含在以下调用之间时才有效:
- (void)beginUpdates;
- (void)endUpdates;
除此之外,行为是未定义的。 (正如您所发现的,相当不可靠)。
编辑:引用《iPhone OS 表格视图编程指南》的相关部分:
要对行和节的批量插入和删除进行动画处理,请在通过连续调用 beginUpdates 和 endUpdates 定义的动画块中调用插入和删除方法。如果不在该块内调用插入和删除方法,行索引和节索引可能无效。 beginUpdates...endUpdates 块不可嵌套。
在块结束时(即 endUpdates 返回后),表视图像往常一样查询其数据源和委托以获取行和节数据。因此,支持表视图的集合对象应该更新以反映新的或删除的行或部分。
iPhone OS 3.0 中引入的 reloadSections:withRowAnimation: 和 reloadRowsAtIndexPaths:withRowAnimation: 方法与上面讨论的方法相关。它们允许您请求表视图重新加载特定部分和行的数据,而不是通过调用 reloadData 加载整个可见表视图。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)