Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 UITableView issue - attempting to set a swipe to delete cell when we already have one

I am seeing an issue with iOS 7. When I bring my UITableView in edit mode - I noticed that I can tap on multiple red "-" button to bring "Delete" option on multiple cells. When this happens I see below warning in console logs. Also, after some operations I am not able to tap on the "-" button.

Works fine in iOS 6.

Is this an iOS7 bug? Do anyone know the workaround for this?

attempting to set a swipe to delete cell when we already have one....that doesn't seem good`

- (BOOL)tableView:(UITableView *)iTableView canEditRowAtIndexPath:(NSIndexPath *)iIndexPath {
    return (self.isEditMode) ? YES : NO;
}


- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)iIndexPath {
    return (iIndexPath.row !=0 && self.isEditMode) ? UITableViewCellEditingStyleDelete : UITableViewCellEditingStyleNone;
}

enter image description here

like image 899
Abhinav Avatar asked Mar 15 '14 15:03

Abhinav


2 Answers

This is an issue with iOS 7 and shall be fixed in next iOS release. Have reported this to Apple.

like image 177
Abhinav Avatar answered Nov 03 '22 01:11

Abhinav


I had this same bug until I changed my method to this:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //remove the deleted object from your data source.
        //If your data source is an NSMutableArray, do this
        [self.array removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }

}

I hope this is helpful to somebody else.

like image 28
DevC Avatar answered Nov 03 '22 01:11

DevC