如何从一个 XIB 中的不同 UIViewController 文件控制第二个 UIView(子视图)
我正在努力完成以下任务。
我试图从另一个 viewController 类控制我的子视图。 我所做的和不起作用的是这个。
我插入了一个对象并将其类更改为我的第二个 viewController 类。 然后我将其 UIButton 出口连接到子视图上的按钮。 然后,我将按钮操作连接到第二个视图控制器的出口。
当我跑步时我得到的是这个。 一切都显示得很好,但是当我尝试触摸子视图中的按钮时,应用程序崩溃了。我只剩下一个令人担忧的问题:“操作不可用:“圆角矩形按钮”的“内部触摸”事件。
这可能是我的逻辑不正确。感谢您的帮助。
I am strugling on the following task.
I am trying to control my subview from another viewController class.
What I did and does not work is this.
I inserted an object and changed it class to my second viewController class.
Then I connected its UIButton outlet to a button I have on my subview.
I then connected the buttons action to the outlet of my second view controller.
What I get when I run is this.
It all shows up well but when I try to touch the button that resides in my subview app crashes. I am only left with a worringing: "Action unavailable: The "Touch Up Inside" event of "Rounded Rect Button".
It's probably my logic that is incorrect. Thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过长时间的研究,我得到了问题的答案。
看来我做的一切都是正确的。
问题是,在初始 XIB 文件初始化后,它会自动释放所有视图和子视图。因此,为了防止释放第二个视图控制器,请
在视图控制器 .m 文件中实现此方法。
此方法将使您的第二个视图控制器保持活动状态,并允许它接收和响应 UI 操作。
Well after a long research I got an answer to my problem.
As it appears I was doing everything right.
The problem is that after the initial XIB file is initialized it autoreleases all views and subviews. So to prevent from gettig your second view controller from being released implement this method
in your view controller .m file.
This method will retain your second view controller alive and allow it to recive and respond to UI actions.