views:

385

answers:

1

Hi everyone,

I have an iPhone app that utilizes TableView to list tagged items that the user has saved. I have Swipe to Delete enabled for these items yet I'm running into an issue with the very first item in the table. All other items show the "Delete" button when swiped, but it does not work for the very first row.

I've searched and searched for an answer to this. I'd appreciate the help!

- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    if([indexPath row] == 0) {
        return UITableViewCellEditingStyleNone;
    }

    return UITableViewCellEditingStyleDelete;
}
+1  A: 

You should return UITableViewCellEditingStyleDelete from tableView:editingStyleForRowAtIndexPath: for all rows that should support delete.

UPDATE
I have explained what your code does in some added comments, so you can see the problem:

- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    if([indexPath row] == 0) {
        // any row that returns UITableViewCellEditingStyleNone will NOT support delete (in your case, the first row is returning this)
        return UITableViewCellEditingStyleNone;
    }

    // any row that returns UITableViewCellEditingStyleDelete will support delete (in your case, all but the first row is returning this)
    return UITableViewCellEditingStyleDelete;
}
gerry3
I am - I've inserted it below:---- (UITableViewCellEditingStyle) tableView: (UITableView *) tableView editingStyleForRowAtIndexPath: (NSIndexPath *) indexPath{ if([indexPath row] == 0) { return UITableViewCellEditingStyleNone; } return UITableViewCellEditingStyleDelete;}
Shawn Farner
I have added your code to your question and explained the problem in my updated answer.
gerry3
Thanks so much for the help, Gerry. Much appreciated. :)
Shawn Farner