4

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).

Asciiom
  • 9,867
  • 7
  • 38
  • 57

2 Answers2

9

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.

Community
  • 1
  • 1
Symmetric
  • 4,013
  • 3
  • 27
  • 33
0

The most common method I use in such cases is to delegate information up the event chain. Set delegates in manner:

subview->cell->table

The second thing you can do is to send a notification via Notificaion Center. Table would listen to any events that forbid normal scrolling. It is overshoot but it will leave your code consistent.

I have no more ideas at the moment.

pro_metedor
  • 1,176
  • 10
  • 17
  • 1
    Can you elaborate on your first suggestion? What would that look like in code? The notification Center hack doesn't seem very clean to me to say the least :) – Asciiom Oct 01 '12 at 12:51