I have a UITableView
as a subview of my UIScrollVIew
, which is the main view controlled by my MainViewController
.
In MainView
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.