4

There are UIButton and UITextField in the UITableViewCell. The delete buttonenter image description here will not come up when I swipe over UIButton or UITextField. I do search for the answers on SO and google, there is a similar questions Swipe left gestures over UITextField, but no correct answers.

I got this problem on iOS 8.

Edit After setting self.tableView.panGestureRecognizer.delaysTouchesBegan = YES;, it works perfect for cell with UITextField. But when i drag start from the UIButton, the delete button shows and the UIButton fired, which I do not want the UIButton get fired.

Community
  • 1
  • 1
lu yuan
  • 7,207
  • 9
  • 44
  • 78
  • i guess you will have to reload tableview after deleting a row – Noor Oct 18 '14 at 06:05
  • @NullData I have update my question. Please make sure you understand what's my problem. – lu yuan Oct 18 '14 at 06:15
  • @NullData nothing special in the code, the cell is created in storyboard, and the cell is editable by return YES in - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath. – lu yuan Oct 18 '14 at 06:27
  • You mean the right most delete button won't show up? I can't reproduce it. – gabbler Oct 18 '14 at 07:00
  • Make sure you swipe on the button. – lu yuan Oct 18 '14 at 07:26
  • @luyuan, Don't see any issue. Works like charm I am using Storyboard. have you added - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath ? – Lightygalaxy Oct 19 '14 at 16:54
  • @Lightygalaxy Yes I implemented it. I have updated my question – lu yuan Oct 20 '14 at 14:30
  • Is `.cancelsTouchesInView` set to `YES` on the gesture recognizer? On a vanilla gesture recognizer, `YES` is the default, but who knows what the `UITableView` sets it to. – ravron Oct 20 '14 at 14:51

1 Answers1

1

I don't know how to prevent the UIButton from firing in the first place, but UITableViewCell has the property showingDeleteConfirmation that can be used to check whether the Delete button is being shown. What I do is check this in the UIButton action for TouchUpInside, like this

- (void)buttonPressed:(id)sender
{
    if (!self.showingDeleteConfirmation) {
        // Handle button press
    }
}

(This example is from a UITableViewCell subclass, so it uses self to access the property.)

This, in addition to the

tableView.panGestureRecognizer.delaysTouchesBegan = YES;

that you already have, works to get the swipe properly recognized and the button action not performed.

JaakkoK
  • 8,247
  • 2
  • 32
  • 50