簡體   English   中英

滾動和插入新行后奇怪的UITableView行為

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM