I am having a table View with a list of category names loaded from the plist. i want to dynamically delete,add and reorder the list and save it to the plist.i used the code below and it is working great on simulator but its crashing on the device.
In ViewDid Load:
self.categoryFile = [[NSBundle mainBundle]pathForResource:@"Categories" ofType:@"plist"];
self.categoryList = [[NSMutableArray alloc]initWithContentsOfFile:self.categoryFile];
- (void)tableView:(UITableView *)tableView commitEditingStyle(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete){
[[self categoryList] removeObjectAtIndex:[indexPath row]];
NSArray *indexPathsToRemove = [NSArray arrayWithObject:indexPath];
[tableView deleteRowsAtIndexPaths:indexPathsToRemove withRowAnimation:UITableViewRowAnimationRight];
[tableView reloadData];
NSArray *newArr = [[NSArray alloc]initWithArray:self.categoryList];
[newArr writeToFile:self.categoryFile atomically:YES];
[newArr release];
}
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath{
NSString *contentsToMove = [[[self categoryList] objectAtIndex:[fromIndexPath row]] retain];
[[self categoryList] removeObjectAtIndex:[fromIndexPath row]];
[[self categoryList] insertObject:contentsToMove atIndex:[toIndexPath row]];
NSArray *newArr = [[NSArray alloc]initWithArray:self.categoryList];
[newArr writeToFile:self.categoryFile atomically:YES];
[newArr release];
[contentsToMove release];
}
The Error is coming at the line writeToFile: atomically.if i remove that line its working on device also but of no use.