Iphone 滚动和插入新行后的奇怪UITableView行为

Iphone 滚动和插入新行后的奇怪UITableView行为,iphone,uitableview,insert,scroll,Iphone,Uitableview,Insert,Scroll,这真的快把我逼疯了 我有一个表视图,它显示一个已排序的客户列表。用户可以添加新客户,因此我必须向表视图添加新行(通过更新数据模型并调用insertRowsAtIndexPaths:withRowAnimation:)。但是,由于表视图是排序的,所以这种插入可能会在屏幕外发生,这不是很好的wrt。用户体验。因此,我的想法是将表视图滚动到索引路径,在实际插入行之前,插入将在该路径中进行: - (void)finishedSavingNewCustomer:(Customer*)customer at

这真的快把我逼疯了

我有一个表视图,它显示一个已排序的客户列表。用户可以添加新客户,因此我必须向表视图添加新行(通过更新数据模型并调用
insertRowsAtIndexPaths:withRowAnimation:
)。但是,由于表视图是排序的,所以这种插入可能会在屏幕外发生,这不是很好的wrt。用户体验。因此,我的想法是将表视图滚动到索引路径,在实际插入行之前,插入将在该路径中进行:

- (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];
}
滚动和插入后的情况:

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行
第2排
第3排
第4排
第5行
---------屏幕顶部--------
第6行
第7排

Row 7a我最近在模拟器上有过一些类似的经历——我正在处理一个从核心数据驱动多个表视图的应用程序,它还通过应用程序的不同点显示了一组UIAlertView和UIActionSheet

我注意到模拟器在UI操作(表格单元格插入、操作表显示等)发生后,对触摸事件的响应不好。这通常对我有帮助

  • 切换到另一个窗口,然后返回模拟器或
  • 点击并拖动鼠标穿过模拟器的非活动区域,然后再次尝试我想要的操作

您的里程可能会有所不同。测试过程中可能会很痛苦,但只要设备上的一切正常,您就应该没事。

您的两个建议对我不起作用,但这肯定是模拟器中的一个错误。即使重新加载表视图也无济于事!无论如何,谢谢分享你的经验。
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 -------