У меня есть TableViewController с SearchBar, отображающий список стран. Пользователь может добавлять свои собственные, а также удалять их. Нормальное удаление из таблицы прекрасно работает, но когда я фильтрую список с помощью uisearchbar и пытаюсь удалить одну из записей, анимация удаления не работает, и система вылетает, когда я выбираю кнопку «Назад». Вот мой commitEditingStyle код:Удалить элемент данных ядра из отфильтрованного tableview вызывает сбой
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.tableView beginUpdates]; // Avoid NSInternalInconsistencyException
Country *countryToDelete;
if (self.searchDisplayController.active) {
//get the country object from the filtered results
countryToDelete = [self.countryResults objectAtIndex:indexPath.row];
//delete the selected item from the filtered results
[self.countryResults removeObject:countryToDelete];
//delete the row which corresponds to the deleted filtered item
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
} else {
countryToDelete = [self.fetchedResultsController objectAtIndexPath:indexPath];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
[self.managedObjectContext deleteObject:countryToDelete];
[self.managedObjectContext save:nil];
[self.tableView endUpdates];
}