Kakuweb Blog Rants and raves. Some interesting stuff, most of it not.

Using a Tap Gesture That Doesn't Interfere with a TableView in iOS

So if you’ve ever used a Tap Gesture on a whole ViewController only to find that it interferes with a TableView and now you can’t select any rows, you know how it can be a pain.

The good news is that there is a really simple way to fix it. You don’t need to create any weird invisble views, etc.

Just add this bit of code in viewDidLoad:

tap.cancelsTouchesInView = false

Where tap is a UIGestureRecognizer object. You can create one in code like this:

let tap = UITapGestureRecognizer(target: self, action: "closeKeyboard")
view.addGestureRecognizer(tap)

Bonus

And a simple way to close the keyboard, as in the above selector is this:

func closeKeyboard() {
    view.endEditing(true)
}
Twitter Share this post if you want, or follow me on Twitter if you're into that stuff.
comments powered by Disqus