如何更改应用程序启动时加载的默认视图控制器?
我有一个应用程序,例如“MyApp”,默认情况下,每当应用程序启动时,它都会加载视图控制器“MyAppViewController”。后来,我向项目添加了一个新的视图控制器“NewViewControler”。
我现在希望“NewViewController”成为我的默认视图控制器,它在应用程序启动时加载。
请让我知道我需要在项目中进行哪些更改才能实现这一目标。
I have an application, say 'MyApp', which by default loads the view controller 'MyAppViewController' whenever the application launches. Later, I added a new view controller 'NewViewControler' to the project.
I now want the 'NewViewController' to be my default view controller which loads when the app launches.
Please let me know what changes I need to make in my project to achieve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这很简单,只需:
Its easy, just:
application:didFinishLaunchingWithOptions:
中,将 NewViewController 的视图而不是 MyAppViewController 的视图添加到窗口。MainWindow.xib
and replace MyAppViewController with NewViewController.application:didFinishLaunchingWithOptions:
add NewViewController's view to the window instead of MyAppViewController's view.您的主 NIB 文件很可能仍设置为“MainWindow”,请检查您的 *-Info.plist 文件。
如果是这种情况,您可以在 Interface Builder 中打开 MainWindow.xib。您应该看到一个视图控制器项目。打开检查器窗口并更改类标识以指向您的新类。这应该负责实例化你的类。
由于这感觉像是一个“新手”问题(如果我弄错了,请原谅我)我还强烈推荐以下文章:
iPhone 编程基础知识:了解视图控制器
帮助我了解整个 ViewController 的事情和 IB 交互。
Most likely your main NIB file is still set to "MainWindow", check your *-Info.plist file.
If that's the case you can open the MainWindow.xib in Interface Builder. You should see a View Controller item. Bring up the inspector window and change the Class Identity to point to your new class. That should take care of instantiating your class.
As this feels like a "newbie" question (please pardon me if I'm mistaken) I would also highly recommend the following article:
iPhone Programming Fundamentals: Understanding View Controllers
Helped me understand the whole ViewController thing and the IB interaction..
对于使用 xcode 4.3.3 的我来说,我所要做的就是简单地将 AppDelegate h 和 m 文件中的“MyAppViewController”的所有引用替换为“NewViewController”。
也许所有其他步骤都已在较新版本的 xcode 中取消。
希望这有帮助。
As for me with xcode 4.3.3, all I had to do was simply replace all references of 'MyAppViewController' with 'NewViewController' in the AppDelegate h and m files.
Perhaps all the other steps have been taken out in the newer versions of xcode.
Hope this helps.