I have a UITableView
with custom UITableViewCells
which contain only a textfield. What I would like to achieve is that the tableview can be scrolled not only by touching the cell itself but also by touching the textfield. The default textfield behaviour to start editing should be preserved. Is there any way to distinguish a scroll gesture on the whole tableview from the tap gesture on the textfield?
I'm not looking for a way to scroll to a specific cell when editing starts but for preserving the default tableview scrolling behaviour.
Regards
I have done it in the following way with subclassing the TableView and overriding the touchesShouldCancel method. The delaysContentTouches and canCancelContentTouches seems to be necessary
class MyTableView : UITableView {
override init(frame: CGRect, style: UITableViewStyle) {
super.init(frame: frame, style: style)
self.delaysContentTouches = false
self.canCancelContentTouches = true
}
override func touchesShouldCancel(in view: UIView) -> Bool {
if view is UITextField {
return true
}
return super.touchesShouldCancel(in: view)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
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