UITableView inside UIScrollView not receiving first tap after scrollling
From Apple Documentation, you shouldn't embed a UITableView
inside a UIScrollView
.
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
Your problem is really related to what your UIScrollView
does.
But if it's just to hide the tableview when needed (that was my case), you can just move the UITableView
in its superview.
I wrote a small example here : https://github.com/rvirin/SoundCloud/
leave the inner UITableView's scrollEnabled
property set as YES
. this lets the inner UITableView
know to handle scroll-related touches on the UIScrollView
correctly.
I ran into this same problem and figured out a solution!!
You need to set the delaysTouchesBegan
to true on your scrollview so that the scrollview sends its failed scrolled-gesture (i.e. the tap) to its children.
var delaysTouchesBegan: Bool
-A Boolean value determining whether the receiver delays sending touches in a begin phase to its view.
When the value of the property is YES, the window suspends delivery of touch objects in the UITouchPhaseBegan phase to the view. If the gesture recognizer subsequently recognizes its gesture, these touch objects are discarded. If the gesture recognizer, however, does not recognize its gesture, the window delivers these objects to the view in a touchesBegan:withEvent: message (and possibly a follow-up touchesMoved:withEvent: message to inform it of the touches’ current locations).
But there's a catch...it doesn't work if you do it directly on the scrollview!
// Does NOT workself.myScrollview.delaysTouchesBegan = true
Apparently this is an iOS bug where setting this property doesn't work (thank you apple). However there's a simple workaround: set the property directly on the scrollview's pan gesture. Sure enough, this worked for me perfectly:
// This works!!self.myScrollview.panGestureRecognizer.delaysTouchesBegan = true