i have a question about the UITableView
delegate function didSelectRowAt
. Everything is working fine but unfortunately the didSelectRowAt
is not called. I read in some other stackoverflow question about the problem and tried some solutions out but none of them works for me. I made a subclass of the tableview which is the delegate himself:
class MyTableView : UITableView, UITableViewDelegate{
override func awakeFromNib() {
super.awakeFromNib()
separatorStyle = .none
backgroundView = nil
backgroundColor = UIColor.clear
isScrollEnabled = false
delegate = self
isEditing = false
allowsSelection = true
}
// func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
//
// this is working
//
// }
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("not called")
}
}
So all subclasses of MyTableView
will implement the datasource stuff and this also working fine (in case somehow will mentioned this).
The strange thing is that didHighlightRowAt
is called, so the delegate somehow works. Only the didSelectRowAt
which I want is not being called.
By the way there aren't any UITapGestureRecognizer
.
Can somehow give me any advice here. Are there properties which are wrong?
tableView(_:didSelectRowAt:)Tells the delegate a row is selected.
Methods for managing selections, configuring section headers and footers, deleting and reordering cells, and performing other actions in a table view.
A view that presents data using rows in a single column. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+
If you have a parent view with gesture recognizer assigned to it you'll need to do something like this:
self.tapGestureRecognizer = UITapGestureRecognizer(target: self, action: action)
if let tapGestureRecognizer = self.tapGestureRecognizer {
tapGestureRecognizer.cancelsTouchesInView = false
self.addGestureRecognizer(tapGestureRecognizer)
}
Once you told the gesture recognizer to stop canceling touches, your UITableView starts reacting on taps as normal
Please check TableView's
cell allowsSelection.
tableView.allowsSelection = true
Edit:
tableView.allowsSelection
cell.selectionStyle
User Interaction Enabled
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With