Nested UITableViews: a way to simultaneously scroll both an external vertical UITableView and a child horizontal UITableView?

When you work with an atypical nested UITableViews setting - where you have an external vertical UITableView that has 90 Β° UITableViews (see Looking for a user interface library to present Data horizontaly in iOS ): is there a way to make the iOS process vertical and horizontal touch at the same time?

I found that iOS is very smart at handling: horizontal touches make the UITableView scroll horizontally, while a vertical swipe makes an external UITableView scroll. Perfect.

Only, I would like to move my finger diagonally and see the external UITableView and scroll the internal UITableView at the same time.

I tried several approaches (playing with canCancelContentTouches, delayaysContentTouches and sensory messages), but I did not find a way to do this.

EDIT: Here's an Xcode4 project that shows this behavior: http://marcanton.io/other/stackoverflow/nestedtableviews.zip

EDIT: I sent this question to Apple Developer Technical Support, here is their answer:

Thank you for writing to Apple Worldwide Developer Support. I am responding to your request regarding touch events in inline UITableViews.

This is usually an approach that is not recommended. The problem is that the UITableView inherits from UIScrollView and as stated in the documentation for UIScrollView:

"Important: you must not embed a UIWebView or UITableView in UIScrollView Objects. If you do so, this may lead to unexpected behavior of the touch event for two objects may be mixed and erroneously processed."

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html%23//apple_ref/occ/cl/UIScrollView

So, this time there is no workaround to scroll at the same time.

I recommend you request an improvement at http://developer.apple.com/bugreporter/ detailing what you would like to see we add in a future release.

However, I think there should be a way to enable this functionality, although I understand that this is not recommended. In fact, Apple does not even recommend placing UITableViews inside another UITableView, but with the exception made above, it works pretty nicely. I will keep this issue up to date with our collective finds.

EDIT: Actually there is a method described in detail here: http://marcanton.io/blog/nested-orthogonal-tableviews/

+4
source share
2 answers

This should be a custom mirroring of intercepted touch events. Touch events, follow the chain of responder chains , which means that if the object in the responder chain (the topmost (appearance)) cannot handle events or actions, it sends a message to the next responder (in this case, the background is a UITableView in the chain). This is why you see horizontal events in a horizontal UITableView and vertical events going to the vertical of a UITableView . The diagonal touch event has applicable horizontal and vertical events, so the topmost view (external vertical UITableView) can respond to vertical touches and swallows the event.

If you think about it, all vertical touches can have some horizontal events (think about when you click your finger), so probably some work is done in the background to determine how to interpret the touch event (either as vertical or horizontal).

I found this protection when passing events to the next object in the responder chain. You might want to give this a try as a partial solution to your puzzle. The rest is to figure out how to capture horizontal touch events and pass them on to the next responder.

+1
source

Interestingly, I have not played with this setting yet, but I would try to capture touch events on nested UITableViews and delegate any vertical movement to an external UITableView - and vice versa.

+1
source

Source: https://habr.com/ru/post/1347709/


All Articles