lu yuan
lu yuan

Reputation: 7227

UIButton & UITextField will block UITableViewCell being swipe to delete

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.

Upvotes: 4

Views: 682

Answers (1)

JaakkoK
JaakkoK

Reputation: 8387

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.

Upvotes: 1

Related Questions