How can I detect a touch on a UITableView
? I tried the solutions in this thread. I have my tableView
and a scrollView
in the same UIViewController
with a constraint, so it is complicated to subclass the tableView
.
The touches methods are not called:
class ViewController: UIViewController, UIScrollViewDelegate, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var verticalSpacing: NSLayoutConstraint!
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var tableView: UITableView!
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
println("touch began")
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
super.touchesMoved(touches, withEvent: event)
}
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
println("touch ended")
}
override func touchesCancelled(touches: NSSet!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
}
I added:
tableView.userInteractionEnabled = true
tableView.canCancelContentTouches = false //or true is the same
but it doesn't change anything. The scrollView
is visible at the same time as the tableView
, but they are not overlapping.