Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. *** Assertion failure in -[UITableView _endCellAnimationsWithContext:],
  2. /SourceCache/UIKit_Sim/UIKit-3347.40/UITableView.m:1623
  3.  
  4. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  5.  
  6. if (editingStyle == UITableViewCellEditingStyleDelete && indexPath.section == 1) {
  7. // Delete cell
  8. [tableView beginUpdates];
  9. [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  10. [tableView endUpdates];
  11.  
  12.  
  13. // Delete LocationCategory from managedObjectContext
  14. LocationCategory *categoryToDelete = [self.locationCategories objectAtIndex:indexPath.row];
  15. [self.managedObjectContext deleteObject:categoryToDelete];
  16. [self.managedObjectContext save:nil];
  17.  
  18. } else if (editingStyle == UITableViewCellEditingStyleInsert) {
  19. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  20. }
  21. }
  22.  
  23. - (void)viewWillAppear:(BOOL)animated {
  24. [super viewWillAppear:animated];
  25.  
  26. self.title = @"Select a Category";
  27.  
  28. // Core Data
  29. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
  30. self.managedObjectContext = [appDelegate managedObjectContext];
  31.  
  32. // Fetch LocationCategories & dump them in an array
  33. NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
  34. [fetchRequest setEntity:[NSEntityDescription entityForName:@"LocationCategory" inManagedObjectContext:self.managedObjectContext]];
  35. NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"categoryName" ascending:YES];
  36.  
  37. NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sortDescriptor count:1];
  38. [fetchRequest setSortDescriptors:sortDescriptors];
  39.  
  40. NSArray *categories = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil];
  41. self.locationCategories = categories;
  42.  
  43. [self.tableView reloadData];
  44. }
  45.  
  46. // This was previously an NSArray. It needs to be an NSMutableArray
  47. @property (nonatomic, strong) NSMutableArray *locationCategories;
  48.  
  49. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  50. if (editingStyle == UITableViewCellEditingStyleDelete && indexPath.section == 1) {
  51. // Delete LocationCategory from managedObjectContext
  52. LocationCategory *categoryToDelete = [self.locationCategories objectAtIndex:indexPath.row];
  53. [self.managedObjectContext deleteObject:categoryToDelete];
  54. [self.locationCategories removeObjectAtIndex:indexPath.row];
  55. [self.managedObjectContext save:nil];
  56.  
  57.  
  58. // Delete cell
  59. [tableView beginUpdates];
  60. [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  61. [tableView endUpdates];
  62.  
  63. } else if (editingStyle == UITableViewCellEditingStyleInsert) {
  64. // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  65. }
  66. }
  67.  
  68. NSArray *categories = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil];
  69. self.locationCategories = [categories mutableCopy];
  70.  
  71. LocationCategory *categoryToDelete = [self.locationCategories objectAtIndex:indexPath.row];
  72. [self.locationCategories removeObjectAtIndex:indexPath.row];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement