I have a tableview with a number of rows that I want to be able to delete. The data that populates the tableview is stored in an NSMutableArray. To delete the data on one row I call:
- (void)deleteFromArray:(NSUInteger) number{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; //load NSUserDefaults
NSMutableArray *storedArray = [[ NSMutableArray alloc] init];
storedArray = [prefs objectForKey: @"mydata"];
[storedArray removeObjectAtIndex:number];
[prefs setObject:storedArray forKey:@"mydata"];
[storedArray release];
[prefs synchronize];
}
From
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
subscribe *subscribeclass = [subscribe alloc];
[subscribeclass deleteFromArray: indexPath.row];
[myTableView reloadData];
}
}
This works fine the first time I delete a row. But when I delete a seconds row the application crashes on the following line in deleteFromArray:
[storedArray removeObjectAtIndex:number];
Any ideas why?