简体   繁体   中英

Touches doesn't work on UITableView inside UIScrollView

I have this strange issue. To start it all, this is how my view hierarchy looks like:

I have a UIViewController with a UIScrollView with three separate ContainerView's inside it. Each of the ContainerView's frames (and respective UIViewControllers ) are set programatically.

I open the second ContainerView with a UIView.animate(...) method. Inside this UIView/UIViewController I have a UITableView . The problem is that only the first five (and half of the sixth for some reason, but maybe that's a clue) UITableViewCell's are selectable. I have about five more UITableViewCell's which is for some reason not selectable.

I don't have any UITapGestureRecognizer's which has been the problem for some other people that I've seen. Also, if I add the TouchesBegan to either the UITableView or the UIViewController holding it, it behaves in the same manner. That will say, it only prints out when I touch the same part of the screen where the UITableViewCell' s are selectable.

Is there anyone that have encountered the same issue or something similar to it that can shed some light over this?

Any help, input or thought is very much appreciated.

So I resolved this issue. For anyone else having similar problems this was because the underlying contentView of the UISrollView wasn't big enough.

Even though the UITableView , and even the views under it was visible, touches could not reach it since these are somehow registered through the UIScrollView contentView (for me, this was an UIView I added in the Interface Builder on top of the UIScrollView ).

Also, if you are working with autoLayout, you have to change the contentViews constraints in the Interface Builder since UIScrollView.contentSize won't bother to listen to your commands.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM