I have a tableView and a delete implemented when swiping to the left (normal way). When I hit the delete button, the record is deleted from the db but not form the view. I want to remove it from the table instantly. In order to see that the record was deleted I need to go back to the previous view and come back again to the tableView and only then the record is gone.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
NewArt *currArt = [self.lN_Dep objectAtIndex:indexPath.row];
self.deptsub = [self.lN_Dep subarrayWithRange:NSMakeRange(indexPath.row, (self.lN_Dep.count - indexPath.row))];
self.selectedURL = [currArt.link absoluteString];
self.selected_ID = (NSString *)currArt.art_ID;
self.selectedArt = currArt;
NSArray *ArrayOfArtIDs_old = [ArtString componentsSeparatedByString:@","];
NSMutableArray *ArrayOfArtIDs_new = [[NSMutableArray alloc]init];
ArrayOfArIDs_new = [[NSMutableArray alloc] initWithArray:ArrayOfArtIDs_old];
for (NSString *item in ArrayOfArtIDs_old) {
if ([item isEqualToString:self.selected_ID]) {
[ArrayOfArtIDs_new removeObject:self.selected_ID];
NSString *updateArt = [self updatedArtIDs:ArrayOfArtIDs_new];
if ([updateArt isEqualToString:@"true"]) {
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[_lN_Dep removeObjectAtIndex:indexPath.row];
//[_lN_Dep removeObject:indexPath];
[self.tableView endUpdates];
}
}
}
[self bookMarkedFeed];
}
The program breaks when I press delete and this line is highlighted.
[_lN_Dep removeObject:indexPath];
or
[_lN_Dep removeObjectAtIndex:indexPath.row];