iOS - 通过代码加载导航控制器
我有一个通过项目向导设置的导航控制器。目前,当应用程序启动时,导航控制器会自动创建并显示。
我现在需要通过代码而不是通过 .xib 魔法来控制导航控制器的显示。如何禁用 MainWindow.xib/RootViewController.xib 的自动创建?我承认我实际上不知道发生了什么以及 MainWindow.xib 和 RootController.xib 之间的关系,因为向导设置了所有这些。
任何有关此的参考或代码片段都会有所帮助。 谢谢!
I have a navigation controller that was setup via the project wizard. Currently when the application is launched the navigation controller automatically gets created and displayed.
I now need to control the display of the navigation controller via code instead of via the .xib magic. How do I disable the automatic creation of the MainWindow.xib/RootViewController.xib? I confess I don't actually know what's going on and the relationship between MainWindow.xib and RootController.xib as the wizard set all this up.
Any references or code snippets on this would be helpful..
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要创建不带笔尖的根导航控制器:
在您的应用程序委托中,您应该看到以下内容:
self.navigationController
指的是从 MainWindow.xib 加载的导航控制器(该文件的名称在您的应用程序的 Info.plist 文件中指定;见下文)。打开 MainWindow.xib 并断开应用程序委托的
navigationController
属性,然后删除对象选项板中的导航控制器(而不是窗口)对象。从 App Delegate 头文件中的
navigationController
@property 声明中删除 IBOutlet 属性(因为它将不再从 nib 文件连接)。将应用程序委托中的代码替换为以下内容:
创建不带笔尖的主窗口:
您可能不需要这样做(并且我不建议这样做),但是因为你(有点)问...
删除MainWindow.xib。
在 main.m 中,将 UIApplicationMain 的最后一个参数替换为您的应用程序委托的名称(不带扩展名)。例如:
打开 Info.plist 文件并删除以下两行:
从 App Delegate 头文件中的
window
@property 声明中删除 IBOutlet 属性。在您的应用程序委托中创建窗口:
To create the root navigation controller without a nib:
In your App Delegate you should see the following:
self.navigationController
refers to the navigation controller that was loaded from MainWindow.xib (the name of this file is specified in your app's Info.plist file; see below).Open MainWindow.xib and disconnect the
navigationController
property of your App Delegate, then delete the Navigation Controller (not the Window) object in the Objects palette.Remove the IBOutlet property from the
navigationController
@property declaration in your App Delegate's header file (since it will no longer be wired from a nib file).Replace the code in your App Delegate with something along the following lines:
To create the main window without a nib:
You probably don't need to do this (and I don't recommend it), but since you (sort of) asked...
Delete MainWindow.xib.
In main.m, replace the last argument to UIApplicationMain with the name of your App Delegate (with no extension). For instance:
Open your Info.plist file and delete the following two lines:
Remove the IBOutlet property from the
window
@property declaration in your App Delegate's header file.Create the window in your App Delegate: