I have a UITableView
as a subview of my UIScrollVIew
, which is the main view controlled by my MainViewController
.
In MainView
My solution is :
set cancelsTouchesInView
To No
of any tapGesture
I found in my custom cell , userInteractionEnable
is set to
NO
, simply delete userInteractionEnable = No
and issue solved.
I have found the answer. I had a UITapGestureRecognizer set for myTableView's superView. This overrode the selection call. Credit to whoever suggested that that might be it. Your answer was deleted before I could mark it correct.
Set the cancelsTouchesInView
property to NO
on the gesture recogniser to allow the table view to intercept the event.
Have you defined instance variable for tableview with same name. If not then might be this can be the issue-
_myTableView.delegate = self;
_myTableView.datasource = self;
Or-
self.myTableView.delegate = self;
self.myTableView.datasource = self;
My problem is the cell is a customized cell, and the action does not work on it. In addition, there is a UITapGestureRecognizer
defined in the superclass.
Firstly,
Set tapGesture.cancelsTouchesInView = false
override func viewDidLoad() {
super.viewDidLoad()
initUI()
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(endEditing))
tapGesture.cancelsTouchesInView = false
view.addGestureRecognizer(tapGesture)
}
Secondly, Instead of setting
isUserInteractionEnabled = true;
in the table view, I set the action on the cell.
In the ViewDidLoad()
super.viewDidLoad()
tableView.delegate = self
}
Then in the
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell: UITableView = tableView.dequeueReusableCell(for: indexPath)
cell.isUserInteractionEnabled = true;
You can try this solution if you are creating a customized cell.
It's work for me, can you try!
let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.dismissKeyboard))
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)
My case is strange. My tableView has 2 sections. 1st section's cells work fine about tableView:didSelectRowAt:
, but 2nd section's cells doesn't trigger didSelectRowAt:
.
The above problem happens at iPhone 4s, iOS 9.3
. But in iPhone 5s, iOS 10.3
, there are no problems, those cells works fine. It seems like iOS 9
bugs about UITableView
.
After many tests, I found out one line codes produces this bug.
tableView.estimatedSectionHeaderHeight = 60.0
Because the 2nd sections has no header view. I remove this line, and all works fine.