I can't figure this out.
I have big UIView
with UITapGestureRecognizer
.
On this view I put (smaller) UITableView
. And now, if I tap on cell,
didSelectRowAt
is not called, because UIView
tap recognizer detect the tap. (It's method is called.)
How do I solve this, that UITableView
don't pass touch through to the view.
I try with setting
table.isUserInteractionEnabled = true
and
table.isExclusiveTouch = true
but it doesn't help
EDIT :
A lot of your answers suggest that I have a tableView below view, which is not the case.
I will paste some of my code (changed a little bit for convenience):
class Panel: UIView {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setTapGesture()
}
func setTapGesture() {
tapGesture = UITapGestureRecognizer.init(target: self, action: #selector(UIControlCenterPanel.tapOnPanel(recogniser:)))
self.addGestureRecognizer(tapGesture)
}
func tapOnPanel(recogniser : UITapGestureRecognizer) {
print("Tap was made")
}
}
class MyPanel: Panel, UITableViewDelegate {
let table = MyTable()
override init(frame: CGRect) {
super.init(frame: frame)
table.table.delegate = self
table.isUserInteractionEnabled = true // This was added as a test
table.table.isExclusiveTouch = true // This was added as a test
table.translatesAutoresizingMaskIntoConstraints = false
addSubview(table)
.... // constraints added below
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("cell tapped")
}
}
class MyTable: UIView {
let table = UITableView()
override init(frame: CGRect) {
super.init(frame: frame)
table.translatesAutoresizingMaskIntoConstraints = false
addSubview(table)
}
}
If I click on the cell now, it print:
Tap was made
If I comment out the gesture recogniser like this :
func setTapGesture() {
// tapGesture = UITapGestureRecognizer.init(target: self, action: #selector(UIControlCenterPanel.tapOnPanel(recogniser:)))
// self.addGestureRecognizer(tapGesture)
}
then it is printed :
cell tapped