У меня есть UITableView, который управляется NSFetchedResultsController.
Строки организованы в разделы из свойства строки. Но когда я изменяю это свойство, приложение завершается с:
Invalid update: invalid number of sections.
Каждая строка представляет кадр в фильме, широкий кадр, крупный план и т. Д.
В строке также указывается, к какой сцене она относится, и из этого рассчитываются разделы.
Shot.m (сущность CoreData)
#pragma mark Transient properties
- (NSString *)sectionIdentifier
{
return [self sceneNumber];
}
ShotsViewController.m (The UITableView)
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> theSection = [[self.fetchedResultsController sections] objectAtIndex:section];
return [theSection name];
}
Я не знаю, что мне здесь делать. Я поиграл с UITableView insertSections и deleteSections, но всегда получаю одно и то же недопустимое количество разделов.
Редактировать
автоматически перемещается в другие существующие разделы:
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
switch(type) {
case NSFetchedResultsChangeInsert:
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
Это сработало после того, как я добавил
case NSFetchedResultsChangeUpdate:
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
Но теперь, скажем, у меня две клетки.
Cell1.sceneNumber = 1
Cell2.sceneNumber = 2
Если я установлю Cell1.sceneNumber = 3, я получу ошибку:
Invalid update: invalid number of sections. The number of sections contained in the table view after the update (3) must be equal to the number of sections contained in the table view before the update (2)