以编程方式添加到情节提要中的 UIView 的子视图不响应操作
我有一个包含许多元素的滚动视图,我必须将它们构建为单独的 xib,因为故事板图形界面正在剪辑它,使我无法使用。
xib 是使用界面生成器构建的,以图形方式将文件的所有者设置为同一视图控制器,允许我按住 Ctrl 键单击并在其中的按钮和方法之间进行链接。
在 viewDidLoad 方法中,视图是这样添加的:
UIView *w = [[[NSBundle mainBundle] loadNibNamed:@"MainView" owner:self options:nil] objectAtIndex:0];
[self.myView.subviewolder addSubview:w];
其中 myView 是主视图,subviewHolder 是 UIScrollView 容器,它们都链接到控制器,子视图被添加并显示得很好。 Self 当然是视图控制器。
似乎没有响应的是视图控制器中链接到我在子视图中的 UIButtons 的操作。我已经设置了一些断点,但流程并没有经过那里。
我缺少什么?
谢谢
I have a scroll view with many elements that I had to build as a separate xib because Storyboards graphic interface was clipping it and made me impossible to work with.
The xib is built with interface builder, setting the file's owner graphically to the same view controller allow me to ctrl-click and link between buttons and methods in it.
The view is added like this in the viewDidLoad method:
UIView *w = [[[NSBundle mainBundle] loadNibNamed:@"MainView" owner:self options:nil] objectAtIndex:0];
[self.myView.subviewolder addSubview:w];
where myView is the main view and subviewHolder is UIScrollView the container, both of them are linked to the controller, and the subview get added and display just fine. Self is of course the view controller.
What seems to not responds are the actions in view controller linked to the UIButtons I have in the subviews. I have put some breakpoints but the flow is just not passing there.
What am I missing ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案非常简单,我做错的是声明子视图持有者的高度比添加的子视图小得多。
我认为 subviewholder 会充当占位符,但它会导致子视图正确显示,但会因与用户交互有关的内容而被“剪辑”,因此从未调用 IBAction。
The answer was really simple, what I did wrong is to declare subviewholder much more smaller in height than the added subviews.
I thought that subviewholder would act as a placeholder, but instead it was causing the subviews to be displayed correctly but 'clipped' for what concerning the user interaction, therefore the IBAction was never called.