Code:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSMutableArray *allTitles = [categories objectForKey:[NSString stringWithFormat:@"%@ Titles", self.title]];
NSMutableArray *customTitles = [NSMutableArray arrayWithArray:
[[NSUserDefaults standardUserDefaults]
arrayForKey:[NSString stringWithFormat:@"Custom Titles %@", self.title]]];
if (indexPath.row >=([allTitles count] - [customTitles count])) {
return;
}
[customTitles removeObjectAtIndex:indexPath.row - (allTitles.count - customTitles.count)];
[[NSUserDefaults standardUserDefaults] setObject:customTitles forKey:[NSString stringWithFormat:@"Custom Titles %@", self.title]];
[[categories objectForKey:[NSString stringWithFormat:@"%@ Titles", self.title]] removeObjectAtIndex:indexPath.row];
[cellTitles removeObjectAtIndex:indexPath.row];
[tableView reloadData];
}
}