使用不同的 XIB 启动应用程序
我想用不同的 Xib 启动我的应用程序。我该怎么做?
谢谢
I want to start my app up with a different Xib. How would I do this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想用不同的 Xib 启动我的应用程序。我该怎么做?
谢谢
I want to start my app up with a different Xib. How would I do this?
Thanks
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
如果您使用的是界面生成器:
在 SupportingFiles 下的 -info.plist 中,查找名为“Main nib file base name”的键。将其更改为您希望它首先加载的 XIB
您还可以将该条目从 plist 中取出,然后在 main.m 中为其指定您的 appDelegate 的名称:
然后在您的 appDelegate 中,您可以根据您的代码手动加载第一个视图控制器和逻辑。就我个人而言,我更喜欢这个,因为它更清晰 - 这是我的委托和加载它的代码。它没有我需要记住的 IB 中的所有绑定。
编辑:
在下面回答您的评论。您粘贴了此无效代码:
那无效。您需要一个实例变量名称。通过将其称为“ViewController”,您尝试调用类成员变量。如果您的类名为 ViewController 那么它应该是:
此时,如果它没有编译,您需要编辑您的问题并将 main.m 和 appDelegate 完全按原样粘贴到问题中。
If you're using interface builder:
Under SupportingFiles, in -info.plist, look for a key named "Main nib file base name". Change that to the XIB you want it to load first
You can also take that entry out of the plist altogether an in main.m give it your appDelegate's name:
Then in your appDelegate, you can manually load your first view controller based on your code and logic. Personally, I like this better because it's much clearer to - here's my delegate and code to load it. It doesn't have all the bindings in IB I need to remember.
EDIT:
Answering your comment below. You pasted this invalid code:
That's not valid. you need an instance variable name. By referring to it as "ViewController" your attempting to call class member variables. If your class is called ViewController then it should be:
At this point, if it's not compiling you need to edit your question and paste your main.m and appDelegate exactly as is into the question.
MainWindow.xib 文件只是一个提供应用程序 UIWindow 的 shell。虽然您可以将 UIViewController 放在 MainWindow.xib 中,但您也可以在应用程序委托上有一个未连接的
UIViewController
出口,并选择在运行时在application:didFinishLaunchingWithOptions:方法,例如:
The MainWindow.xib file is just a shell that provides the application's UIWindow. While you can put a UIViewController in MainWindow.xib, you can also just have an unconnected
UIViewController
outlet on your app delegate and pick which nib to load at runtime in yourapplication:didFinishLaunchingWithOptions:
method, e.g.: