I am trying to create a UITableViewCell
which has a horizontally scrollable UIScrollView
. How to make sure that when user touches on the UIScrollView
, the UITableViewCell
gets selected.
The UITableViewCell
has a UIScrollView
as a subview as well as some other subviews. When user taps on non-UIScrollView
subviews, the cell gets selected as expected.
However, when user taps on the UIScrollView
, nothing happens.
The UIScrollView
has some sub views. The user can horizontally scroll the scrollview as expected.
Is there any way such that, when user flicks through the UIScrollView
, the UIScrollView
handles the touch event, but when user taps on the UIScrollView
, it passes the event to the superview?
Edit -
I tried overriding touchesEnded(_:with:)
as follows -
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
superview?.touchesEnded(touches, with: event)
}
It did not work
Secondly, I tried adding a UITapGestureRecognizer
to the scrollview and check if detects the taps.
It does detect the tap. However, in order to select the UITableViewCell
, I need to get the respective UITableViewCell
for the scrollview, find its indexPath and then using the UITableView
select that indexPath.
I am hoping if there is a simpler way to perform what I am trying to achieve.