Поэтому я использую NSFetchedResultController для отображения данных в моей таблице.Я получаю уведомление об обновлении, и оба индекса и newIndex установлены.Так что же представляют эти два индекса во время обновления?и Почему я получаю значения для обоих в уведомлении об обновлении?Разве newIndex не только для уведомления о перемещении?
Когда я пытаюсь получить доступ к объекту по индексу [24, 4], я получаю сбой, потому что, очевидно, объект не существует в этом indexPath.есть идеи, что здесь происходит?
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
switch(type)
{
case NSFetchedResultsChangeInsert:
[_tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self configureCell:[_tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[_tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex
forChangeType:(NSFetchedResultsChangeType)type
{
switch(type)
{
case NSFetchedResultsChangeInsert:
[_tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[_tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)configureCell:(MyCustomCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
// Crashes on the line below, before calling setBook
Book *book = [_fetchedResultController objectAtIndexPath:indexPath];
[cell setBook:book];
}
Результат во время обновления, прямо перед моим сбоем:
indexPath [24, 4]
newIndexePath [32, 4]