0
votes

I have a UITableView with static cells and grouped style in my UIViewController. I added a UIGestureRecognizer, that I can dismiss the Keyboard, but I want to except the UIGestureRecognizer for several UITableViewCells, because they have a functionality when they get selected.

My code:

The class - variable that I can use it everywhere in the code:

    var tap:UITapGestureRecognizer = UITapGestureRecognizer()

My viewDidLoad() Method:

override func viewDidLoad() {
    super.viewDidLoad()

    self.tap = UITapGestureRecognizer(target: self, action: "DismissKeyboard")
    tableView.addGestureRecognizer(tap)
}

And the Action of the UIGestureRecognizer:

func DismissKeyboard()
{
    print("is here")
    if(self.keyboardIsVisible)
    {
        view.endEditing(true)
        self.refreshTableView()
    }
}

I removed the Gesture Recognizer of one cell in the override func cellForRowAtIndexPath:

 cell.removeGestureRecognizer(self.tap)

But when I tap this cell it still goes into the DismissKeyboard - Action...

2

2 Answers

0
votes

You add your UITapGesgureRecognizer to tableView and you try remove from de cell. Try use tableView.removeGestureRecognizer(self.tap)

0
votes

Instead of Adding Tap Gesture on TableView Cell or TableView. you can Add Custom UIButton on UITableViewCell and Add Target to it. You can then disable Table view's didSelectRowatIndexPath event. You can write your code on button click events.