UITabBarController 子视图的文件所有者

发布于 2024-11-30 08:17:04 字数 842 浏览 1 评论 0原文

我遵循了这个 UITabBarController 教程 主要使用 Interface Builder 创建一个带有相应子视图的选项卡栏。 UITabBarController 是在那里创建的,选项卡的视图控制器也在那里添加。

我是否正确地认为创建 UIViewControllers {WelcomeViewController|AboutViewController}.{h|m} 是不必要的?

谁是子视图 {WelcomeViewController|AboutViewController}.xib 的真正文件所有者

请注意,我首先尝试在 WelcomeViewController.h 中创建 IBAction 方法:在 WelcomeViewController.xib 的 Interface Builder 中,我可以将按钮按下连接到该操作,就像它出现在文件所有者中一样。但在运行时它崩溃了,因为真正的文件所有者可能不是WelcomeViewController.m的对象。我在这儿吗? IBAction出现在Interface Builder(此处为Xcode 4)中是一个错误吗?

最后一个问题:当我像教程中那样在 Interface Builder 中连接所有内容时,如何/仍然可以分离代码(在 WelcomeViewController.h 中具有 IBActions,用于仅发生在该子视图上的操作)?

I followed this UITabBarController Tutorial which creates a Tab Bar with according subviews mostly using Interface Builder. The UITabBarController is created there and the Tab's View Controllers are added there too.

Am I correct that creating the UIViewControllers {WelcomeViewController|AboutViewController}.{h|m} is unnecessary?

Who is the real File's Owner of the Subviews {WelcomeViewController|AboutViewController}.xib?

Note that I at first tried to create an IBAction method in WelcomeViewController.h: in Interface Builder at WelcomeViewController.xib, I could connect a button press to that action as it appeared at File's Owner. But at runtime it crashed, as the real File's Owner presumably is not an Object of WelcomeViewController.m. Am I right here? Is it a bug that the IBAction appears in Interface Builder (Xcode 4 here)?

A last question: How/can I still separate code (having IBActions in WelcomeViewController.h for actions that happen only on this subview) when I connect everything up in Interface Builder like in the tutorial?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

花海 2024-12-07 08:17:04

我认为创建 UIViewControllers {WelcomeViewController|AboutViewController}.{h|m} 是不必要的,对吗?

不,两个控制器都是必要的,因为每个全屏窗口应该至少(并且最好最多)一个 ViewController 来管理视图层次结构。 TabBarController 只是一种“哑”元控制器,管理它加载的子控制器的显示 - 因此您需要用于切换视图的控制器。我建议您阅读Apple 文档的这一部分

谁是子视图 {WelcomeViewController|AboutViewController}.xib 的真正文件所有者?

文件的所有者应该是相应的控制器类(在您的情况下,{WelcomeViewController|AboutViewController}.{h|m}) - 当选择文件的所有者时,您可以在检查器调色板的 Interface Builder 中设置该类。只有在应用程序启动时打开的第一个窗口(通常称为 Main.xib 等)才应将应用程序委托作为文件的所有者。文件的所有者拥有 XIB/NIB 文件的对象 - 对象引用方面,你知道我的意思:) 我认为也应该可以使用其他控制器加载 XIB/NIB 文件(并且其他控制器自动成为文件的对象)楼主),但我不确定。

...我在吗? IBAction 出现在 Interface Builder(此处为 Xcode 4)中是否是一个错误?

您可能在 Interface Builder 中以错误的方式连接操作,这是一个常见的错误。尝试按住 Ctrl 键,然后将一条线从按钮拖到文件所有者上,然后选择所需的链接方法。应该可以做到这一点。

最后一个问题:当我像教程中那样在 Interface Builder 中连接所有内容时,如何/仍然可以分离代码(在 WelcomeViewController.h 中具有 IBActions,用于仅发生在该子视图上的操作)?

我想我在第一段中回答了这个问题 - WelcomeViewController 仍然存在,您所要做的就是创建 IBOutlet 并将它们连接到 IB 中。当然,您也可以通过编程方式进行连接,因为成员“视图”是自动填充的(通过文件所有者连接),并且所有子视图都可以从那里访问。

Am I correct that creating the UIViewControllers {WelcomeViewController|AboutViewController}.{h|m} is unnecessary?

No, both controllers are necessary, since there should be at least (and, optimally, at most) one ViewController per full-screen window to manage your view hierarchy. The TabBarController is only a kind of "dumb" meta-controller managing the display of the sub-controllers it loads - therefore you need controllers for the views which are switched. I would recommend you read this part of the Apple doc.

Who is the real File's Owner of the Subviews {WelcomeViewController|AboutViewController}.xib?

The File's Owner should be the corresponding controller class (in your case, {WelcomeViewController|AboutViewController}.{h|m}) - you can set the class in Interface Builder in the inspector palette when File's Owner is selected. Only the very first window (usually called Main.xib or so) which is opened at application start should have the application delegate as File's Owner. File's Owners own the objects of the XIB/NIB file - object-reference wise, you know what I mean :) I think it should also be possible to load the XIB/NIB file with other controllers (and the other controller automatically becoming the File's Owner), but I'm not sure.

... Am I right here? Is it a bug that the IBAction appears in Interface Builder (Xcode 4 here)?

It may be that you wired up the action the wrong way in Interface Builder, a common mistake. Try holding the Ctrl key, then drag a line from the button onto the File's Owner, and choose the desired method to link to. That should do it.

A last question: How/can I still separate code (having IBActions in WelcomeViewController.h for actions that happen only on this subview) when I connect everything up in Interface Builder like in the tutorial?

I think I answered this in the first paragraph - WelcomeViewController is still there and all you have to do is create IBOutlets and wire them up in IB. Of course, you can also do the wiring programmatically, since the member "view" is automatically populated (via the File's Owner connection), and all subviews are accessible from there.

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