Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent UITableView from scrolling when custom subview is handling touches

In my iOS app have a UITableView which contains a custom subview in one of it's cells. This cell is an interactive view that handles touch events (touchesBegan, touchesEnded, touchesMoved) to update itself.

The problem is that when the user 'drags' up or down, the tableView catches these touches (although I don't pass the touches up the responder chain), scrolls the table and prevents the subview from working correctly. I would like to prevent the table from scrolling as long as the user is touching that particular subview.

The subview has no reference at all to the tableView.

How can I prevent the scrolling behavior of the table?


Update

Despite accepting the answer below, I ended up handling my situation differently. I handle the touch events in my custom view now, pass them up the responder chain (to the table cell), the cell handles the touch events as well, using them to enable/disable scrolling on the superview (the table).

like image 780
Asciiom Avatar asked Jan 16 '23 10:01

Asciiom


1 Answers

Turning off "Cancellable Content Touches" in the UITableView solved this for me (in the UITableView attributes inspector under Scroll View / Touch). I got this from this SO question: Scrolling a UITableView inside a UIScrollView

From the UIScrollView:canCancelContentTouches doc:

If the value of this property is NO, the scroll view does not scroll regardless of finger movement once the content view starts tracking.

like image 196
Symmetric Avatar answered Jan 30 '23 12:01

Symmetric