How to change the default View Controller that is loaded when app launches?

前端 未结 4 1101
别那么骄傲
别那么骄傲 2021-01-05 16:39

I have an application, say \'MyApp\', which by default loads the view controller \'MyAppViewController\' whenever the application launches. Later, I added a new view control

相关标签:
4条回答
  • 2021-01-05 16:53

    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..

    0 讨论(0)
  • 2021-01-05 16:56

    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.

    0 讨论(0)
  • 2021-01-05 17:05

    Its easy, just:

    • Open your Storyboard
    • Click on the View Controller corresponding to the view that you want to be the initial view
    • Open the Attributes Inspector
    • Select the "Is Initial View Controller" check box in the View Controller section
    0 讨论(0)
  • 2021-01-05 17:06
    1. Open MainWindow.xib and replace MyAppViewController with NewViewController.
    2. In your app delegate class, replace the property for MyAppViewController with one for NewViewController. Connect NewViewController to its new outlet in Interface Builder.
    3. In application:didFinishLaunchingWithOptions: add NewViewController's view to the window instead of MyAppViewController's view.
    0 讨论(0)
提交回复
热议问题