我有一個UITableView與3節,每節通過獨特的NSFetchedResultsController饋送。UITableView與多個NSFetchedResultsControllers導致斷言失敗
我從NSFetchedResultsController -controllerDidChangeContent,插入時,更新...表得到斷言失敗。
我的猜測是indexPaths出現在下面的方法中,因爲每個控制器只有單個部分(0),而對於部分0中的控制器,失敗不會發生。
- (void)controller:(NSFetchedResultsController*)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath*)newIndexPath
{
switch(type)
{
case NSFetchedResultsChangeInsert:
[[self atableView] insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationLeft];
break;
case NSFetchedResultsChangeDelete:
[[self atableView] deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
break;
case NSFetchedResultsChangeUpdate:
[self configureCell:(DashboardViewCell *) [[self atableView] cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[[self atableView] deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[[self atableView] insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
所以我的問題是,我怎麼能確定哪個控制器(從部分)正在處理,並相應修改indexPath如果是那樣的做這件事的正確方法嗎?可能有任何使用多個nsfetchedresults控制器和一個uitableview的示例。
感謝您節省時間;)`newIndexPath`的一個小錯誤。它應該是`[NSIndexPath indexPathForRow:newIndexPath.row inSection:]` –
2012-12-13 08:12:14