[英]Weird UITableView behavior after scrolling and inserting new row
这真让我疯狂。
我有一个表视图,显示一个排序的客户列表。 用户可以添加新客户,因此我必须向表视图添加一个新行(通过更新数据模型并调用insertRowsAtIndexPaths:withRowAnimation:
。 但是,由于表视图已排序,因此此插入可以在屏幕外进行,这不是很好。 用户体验。 所以我的想法是在实际插入行之前将表视图滚动到插入将发生的索引路径:
- (void)finishedSavingNewCustomer:(Customer*)customer atIndex:(NSInteger)index {
// NOTE: self.customers (which is the model for the table view used in all datasource
// methods) has already been updated at this point, ie. it already contains the new customer
// scroll the table view so that the insert position is on-screen
NSInteger scrollRow = (index < ([self.customers count] - 1) ? index : [self.customers count] - 2);
NSIndexPath* scrollIndexPath = [NSIndexPath indexPathForRow:scrollRow inSection:0];
[self.tableView scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionNone animated:NO];
// insert the new row
NSArray* indexPaths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:index inSection:0]];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
}
此代码实际上按预期工作:表视图滚动并正确插入新行。
然而,在插入之后,一些表视图单元变得“无响应” ,即。 它们不会在滑动时显示删除按钮,甚至在选中时也不会突出显示。 由于这真的很奇怪,有点难以解释,让我试着说明一下。
初始情况:显示行1 - 5:
--------- screen top --------
Row 1
Row 2
Row 3
Row 4
Row 5
------- screen bottom -------
Row 6
Row 7
Row 8
Row 9
滚动和插入后的情况:
Row 1
Row 2
Row 3
Row 4
Row 5
--------- screen top --------
Row 6
Row 7
Row 7a << newly inserted
Row 8
Row 9
------- screen bottom -------
现在,在插入行1-5之后将不响应如上所述的用户交互。
有人遇到过这种问题吗? 想法? 是否有其他方法可确保用户可以看到新行的插入?
更新:刚刚在设备上测试过,事实证明这个问题只发生在模拟器上! 这使问题不那么令人不愉快,但如果其他人遇到这种行为,我仍然会感兴趣。
我最近在Simulator上有过类似的经历 - 我正在处理一个从Core Data驱动几个表视图的应用程序,它还通过应用程序在不同的点上展示了一堆UIAlertViews和UIActionSheets。
我注意到,在UI动作(表格单元格插入,操作表显示等)发生后,模拟器对触摸事件的响应不佳。 它通常对我有帮助
你的旅费可能会改变。 测试过程中可能会很痛苦,但只要设备上的一切正常,就应该没问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.