tags:

views:

36

answers:

0

When I go into edit mode and reorder the cells in the table everything is fine. But when I reorder cells AND delete a row the app usually crashes: "SIGABRT". I'm using a displayOrder attribute in Core Data to keep track of the order of my rows.

GDB tells me that the problem is when I try to save the order:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];

    [self.tableView setEditing:editing animated:animated];

    if (!editing) {
       int i = 0;
       for (Course *rowObject in orderArray) {
         **rowObject.displayOrder = [NSNumber numberWithInt:i++];**
       }
       self.navigationItem.rightBarButtonItem.enabled = YES;

    } else {
        self.navigationItem.rightBarButtonItem.enabled = NO;
    }

    // Save the context.
    NSError *error;
    if (![managedObjectContext save:&error]) {
        // Update to handle the error appropriately.
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        exit(-1);  // Fail
    }   
}

rowObject.displayOrder = [NSNumber numberWithInt:i++]; is where it always crashes.

Another interesting thing is that Instruments gives me another, yet similar, problem area.

- (void)viewWillAppear:(BOOL)animated {

    // For ordering the rows
    NSArray *fetchedArray = [fetchedResultsController fetchedObjects];
    **orderArray = [[NSMutableArray alloc] initWithArray:fetchedArray];**

    [self.tableView reloadData];
}

orderArray = [[NSMutableArray alloc] initWithArray:fetchedArray]; This is the other crash point.

Any ideas on why this could be crashing? Thanks.