如何从一个 XIB 中的不同 UIViewController 文件控制第二个 UIView(子视图)

发布于 2024-09-27 22:13:49 字数 303 浏览 1 评论 0 原文

我正在努力完成以下任务。

我试图从另一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜兔 2024-10-04 22:13:49

经过长时间的研究,我得到了问题的答案。
看来我做的一切都是正确的。

问题是,在初始 XIB 文件初始化后,它会自动释放所有视图和子视图。因此,为了防止释放第二个视图控制器,请

 - (void)awakeFromNib {
    [self retain];
}

在视图控制器 .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

 - (void)awakeFromNib {
    [self retain];
}

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文