Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 223
NSExplorer Avatar asked Feb 02 '11 16:02

NSExplorer


3 Answers

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
like image 147
Pepe Ramirez Avatar answered Nov 15 '22 06:11

Pepe Ramirez


  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.
like image 35
Ole Begemann Avatar answered Nov 15 '22 07:11

Ole Begemann


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

like image 43
loafoe Avatar answered Nov 15 '22 06:11

loafoe