gpt4 book ai didi

objective-c - 我如何将导航 Controller 添加到 xib

转载 作者:可可西里 更新时间:2023-11-01 03:09:37 26 4
gpt4 key购买 nike

在找不到任何关于如何为 xibs 执行此操作的教程之前,我只使用故事情节来子类化导航 Controller 。

如何将导航 Controller 添加到某个 xib,以便我可以对其进行子类化?然后我可以覆盖我的 View 的旋转。我坚持的部分是 View Controller 如何知道导航 Controller ?在 Storyboard中,我会手动将它连接到我的 View Controller 。我只是不能用 xibs 解决它?

我在我的 View xib 旁边添加了一个导航 Controller ...现在我需要这里的一些建议。

我还从我原来的 iPhone xibs 创建了 iPad View 。当我从 IB 拖动导航 Controller 时,它仍然是 iPhone 屏幕尺寸吗?

最佳答案

您不需要像在 Storyboard中那样在 xib 文件中设置 UINavigationController,因为 xib 只代表一个屏幕。正常的做法是分配/初始化一个 UINavigationController 和一个 UIViewController,并在显示之前将 View Controller 设置为导航 Controller 的根。如果您希望整个应用从一开始就包装在导航 Controller 中,则可以在 App Delegate 中完成此操作。

在 Non-Storyboard 应用程序的应用程序委托(delegate)中,您可能需要这样的东西

self.navigation = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]];

[self.window makeKeyAndVisible];

self.window.rootViewController = self.navigation;

其中 self.navigation 是一个 UINavigationController 属性或属于 App Delegate 的 iVar。如果您想在 xib 中正确设置 View Controller ,请选择 xib 中的 Root View 并打开属性检查器(RHS,看起来像一个小盾牌的那个)并在“顶部栏”中选择“导航栏”下拉式菜单。这将在 xib 中显示一个导航 Controller 顶部栏,因此您可以相应地定位其他 View 。

编辑

这不完全正确,您可以在 xib 文件中创建导航 Controller ,但我一直认为它比它值得的麻烦更多,因为它的视觉元素很少,而且它们可以在代码中非常很容易。

本教程的更多信息在这里

http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/

关于objective-c - 我如何将导航 Controller 添加到 xib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13931994/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com