简体   繁体   English

UIScrollView点击手势不起作用

[英]UIScrollView tap gesture not working

I have an application where I am creating and adding PrimaryViewController to a UIScrollView , when the user taps on a button on PrimaryViewController 's view, I create and add a SecondViewController to the UIScrollView . 我有一个要在其中创建PrimaryViewController并将其添加到UIScrollView的应用程序,当用户点击PrimaryViewController的视图上的按钮时,我会创建一个SecondViewController并将其添加到UIScrollView The SecondViewController creates and adds a new UIScrollView to it's view. SecondViewController创建一个新UIScrollView并将其添加到其视图中。

My problem is this: I need to get a tap event on the SecondViewController 's UIScrollView. 我的问题是:我需要在SecondViewController的UIScrollView上获得一个点击事件。 But when I tap on the SecondViewController 's UIScrollView it throws an error (unrecognized selector). 但是,当我点击SecondViewControllerUIScrollView它将引发错误(无法识别的选择器)。 I believe it has to do with the view hierarchy and the fact that I am creating a new SecondViewController each time the button on PrimaryViewController 's view is tapped (which I need to do). 我相信这与视图层次结构有关, SecondViewController每次点击PrimaryViewController的视图上的按钮时,我SecondViewController创建一个新的SecondViewController (这是我要做的)。 Does anyone know how to solve this view-hierarchy issue? 有谁知道如何解决这个视图层次问题? If you need more of an explanation let me know. 如果您需要更多解释,请告诉我。

A friend helped me solve my issue. 一位朋友帮助我解决了我的问题。 I was creating a new SecondViewController each time the PrimaryViewController's button was tapped. 每次点击PrimaryViewController的按钮时,我都会创建一个新的SecondViewController。 I changed it so I just update the data in the SecondViewController instead of creating an entirely new view controller. 我更改了它,所以我只更新了SecondViewController中的数据,而不是创建一个全新的视图控制器。 I still don't quite understand the problem, but will update this post if I figure out why. 我仍然不太清楚这个问题,但是如果我找出原因,将会更新这篇文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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