Hi again!
Actually I'm trying to delete a row, when it's dragged to the bottom.
I keep my data in a mutable array and it's initialized by my initialization method "initData" which is called in the method "viewDidLoad" and reinitialized in the "controllerDidChangeContent:(NSFetchedResultsController *)controller" method.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
if( fromIndexPath == toIndexPath ) {
return;
}
id element = [self.data objectAtIndex:fromIndexPath.row];
if (toIndexPath.row == [self.data count] -1) { //element has been dragged to the bottom
[self.data removeObjectAtIndex:fromIndexPath.row];
@try {
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:fromIndexPath] withRowAnimation:UITableViewRowAnimationBottom];
[self.tableView endUpdates];
}
@catch (NSException * e) {
NSLog([NSString stringWithFormat:@"Exception thrown while moving tableviewcell to the End of the table \nName: %@; Reason: %@; userInfo: %@", [e name], [e reason], [e userInfo]]);
}
}
else { //Normal reoder operation
[self.data removeObjectAtIndex:fromIndexPath.row];
[self.data insertObject:element atIndex:toIndexPath.row];
}
}
This is my initData method as mentioned before.
-(void) initData {
self.data = [[NSMutableArray alloc] init];
[self.data addObjectsFromArray:[self.fetchedResultsController fetchedObjects]];
}
So I get my displayed elements from the core data, but I can't display the core data because I need to add several elements later.
I always have data in my core data (because some elements can't be deleted) and are not removed anywhere else.
Sometimes it works pretty fine. Sometimes i get the "Attempt to create two animations for cell" exception.
Sorry for my previouse post with no code.
And thanks for all in advance for your help!
Nicolay