我有一個tableView使用NSFetchedResultsController來填充viewDidLoad上的表格單元格。用戶可以使用UISegmentControl(index 0 ='number',index 1 ='name')對tableView進行排序。NSFetchedResultsController didChangeObject排序後使用了錯誤的indexPath
當用戶單擊UISegmentControl時,它調用函數sortShortListUsingSelectedSortIndex
,此函數將使用setSortDescriptors
和NSFetchedResultsController
重新排序tableView。當表格被重新排序並且用戶選擇一行時,didSelectRowAtIndexPath:
顯示我期望看到的NSIndexPath
(例如,IndexPath [0,6]被重新排序爲Index [0,3]),但是當試圖刪除相同的排在NSIndexPath
在didChangeObject:atIndexPath:forChangeType:newIndexPath
顯示舊IndexPath [0,6]不[0,3],並會導致崩潰:
CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (9) must be equal to the number of rows contained in that section before the update (9), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)
這裏是我的方法的簡化版本:Gist
我爲什麼在我的tableView中看到同一行的不同索引?