0

I'm trying to implement the swipe left to display the delete button. The cell moves left, but there are no visible buttons. Why does this happen? What is the solution?

To be clear, I have searched on StackOverflow and tried at least a dozen posted "solutions", but none of them have worked for me.

Thanks in advance.

I tried using the following code, which does seem to make the table cell move, but the log does not show NSLog(@"commitEditingStyle");. Why does this happen?

// Swipe to delete.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"commitEditingStyle");
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSLog(@"UITableViewCellEditingStyleDelete");
        [listData removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self.tableView reloadData];
    }
}

And I have tried adding:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{

    return YES;
}

Here is a screenshot:

No delete button

Mark
  • 564
  • 4
  • 12
  • Have a look at this: http://stackoverflow.com/questions/24142591/swipe-to-expose-more-flag-archive-buttons-like-in-mail-app-on-ios-8. I think if you would search here in this community you would find a lot working examples... – dehlen Dec 24 '14 at 09:53
  • http://stackoverflow.com/questions/19164188/custom-edit-view-in-uitableviewcell-while-swipe-left – Sport Dec 24 '14 at 09:54
  • Please use self.tableView.allowsMultipleSelectionDuringEditing = NO; – Uttam Kadam Dec 24 '14 at 09:55
  • @dehlen I thought I did implement the two necessary functions: `- tableView:editActionsForRowAtIndexPath:` `- tableView:commitEditingStyle:forRowAtIndexPath:` I also tried the method suggested in the github. No change unfortunately. – Mark Dec 24 '14 at 10:01
  • @UttamKadam : I also tried `self.tableView.allowsMultipleSelectionDuringEditing = NO;`. No change. – Mark Dec 24 '14 at 10:02
  • @user1736436: which Xcode version you are using. – Vineesh TP Dec 24 '14 at 10:27

2 Answers2

0

The problem was that the table size was larger than my screen size. The solution is to set the constraints to match the width of the view.

Mark
  • 564
  • 4
  • 12
0
// During startup (-viewDidLoad or in storyboard) do:
self.tableView.allowsMultipleSelectionDuringEditing = NO;

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return YES if you want the specified item to be editable.
    return YES;
}

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //add code here for when you hit delete
    }    
}
Uttam Kadam
  • 458
  • 1
  • 7
  • 20