У меня есть приложение, которое показывает пользовательскую ячейку, в которой еще нет данных, когда пользователь впервые запускает приложение.
Когда пользователь делает первую запись, обновляется fetchedResults моего fetchedResultsController, что вызывает отсутствие-data-все же ячейка для удаления и ячейка данных для вставки.
это использовалось в прошлом (iPhone 3.x).Теперь на iOS 4.2 это вызывает сбой после вызова endUpdates.Нет информации об исключениях или какой-либо понятной трассировки стека.Я только знаю, что сбой вызван в _CFTypeCollectionRetain (возможно, при попытке сохранить NULL)
Любые идеи, как действовать?
вот соответствующий код:
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
NSLog(@"starting updates");
[self.tableView beginUpdates];
}
- (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;
}
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
UITableView *tv = self.tableView;
[tv reloadData];
switch(type) {
case NSFetchedResultsChangeInsert:
NSLog(@"insert");
if ([self.tableView numberOfRowsInSection:newIndexPath.section] == 1 &&
[[self.fetchedResultsController fetchedObjects] count] == 1)
{
NSLog(@"reloading row %d", newIndexPath.row);
[tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
[tv insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else {
NSLog(@"inserting new row %d", newIndexPath.row);
[tv insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
}
break;
case NSFetchedResultsChangeDelete:
NSLog(@"delete");
if ([self.tableView numberOfRowsInSection:newIndexPath.section] == 0 &&
[[self.fetchedResultsController fetchedObjects] count] == 0)
{
NSLog(@"reloading row %d", newIndexPath.row);
[tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
[tv insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else {
NSLog(@"deleting row %d", newIndexPath.row);
[tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
NSLog(@"finishing updates");
[self.tableView endUpdates];
}