Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *** Assertion failure in -[UITableView _endCellAnimationsWithContext:],
- /SourceCache/UIKit_Sim/UIKit-3347.40/UITableView.m:1623
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- if (editingStyle == UITableViewCellEditingStyleDelete && indexPath.section == 1) {
- // Delete cell
- [tableView beginUpdates];
- [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
- [tableView endUpdates];
- // Delete LocationCategory from managedObjectContext
- LocationCategory *categoryToDelete = [self.locationCategories objectAtIndex:indexPath.row];
- [self.managedObjectContext deleteObject:categoryToDelete];
- [self.managedObjectContext save:nil];
- } else if (editingStyle == UITableViewCellEditingStyleInsert) {
- // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
- }
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- self.title = @"Select a Category";
- // Core Data
- AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
- self.managedObjectContext = [appDelegate managedObjectContext];
- // Fetch LocationCategories & dump them in an array
- NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
- [fetchRequest setEntity:[NSEntityDescription entityForName:@"LocationCategory" inManagedObjectContext:self.managedObjectContext]];
- NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"categoryName" ascending:YES];
- NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sortDescriptor count:1];
- [fetchRequest setSortDescriptors:sortDescriptors];
- NSArray *categories = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil];
- self.locationCategories = categories;
- [self.tableView reloadData];
- }
- // This was previously an NSArray. It needs to be an NSMutableArray
- @property (nonatomic, strong) NSMutableArray *locationCategories;
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
- if (editingStyle == UITableViewCellEditingStyleDelete && indexPath.section == 1) {
- // Delete LocationCategory from managedObjectContext
- LocationCategory *categoryToDelete = [self.locationCategories objectAtIndex:indexPath.row];
- [self.managedObjectContext deleteObject:categoryToDelete];
- [self.locationCategories removeObjectAtIndex:indexPath.row];
- [self.managedObjectContext save:nil];
- // Delete cell
- [tableView beginUpdates];
- [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
- [tableView endUpdates];
- } else if (editingStyle == UITableViewCellEditingStyleInsert) {
- // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
- }
- }
- NSArray *categories = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil];
- self.locationCategories = [categories mutableCopy];
- LocationCategory *categoryToDelete = [self.locationCategories objectAtIndex:indexPath.row];
- [self.locationCategories removeObjectAtIndex:indexPath.row];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement