Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the initial view controller of storyboard?

Tags:

ios

I have 2 view controller ,and I disabled the initial view controller of first view controller ,and enabled the second view controller,but when start the project,the initial view controller is still the first view controller ,what should I do? Thanks!

like image 849
Anh73 Avatar asked Apr 17 '16 13:04

Anh73


People also ask

How do I change my initial view controller?

You will be able to see how your Initial View Controller currently looks like on the left side of your screen. Simply drag the View Controller to the screen to create a new one; this option is located on the bottom-right side of the screen.

How do I change the name of a view controller scene?

To change the name of the view controller follow the simple steps. Step 2: Press and hold the control key on the keyboard and press the right click of the mouse. Step 3: A drop-down menu will occur then select refactor in the dropdown. After selecting refactor another dropdown menu will occur select Rename in that.


3 Answers

Tap the second view controller, and select "Is initial View Controller" in Attributes inspector.

enter image description here

like image 181
Surya Subenthiran Avatar answered Nov 16 '22 16:11

Surya Subenthiran


Alternatively you can do this with code too. In your AppDelegate class's didFinishLaunchingWithOptions method you can write

let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let secondVC = storyBoard.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController
self.window?.rootViewController = secondVC

Edit
Swift 3.0

let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let secondVC = storyBoard.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController
self.window?.rootViewController = secondVC

Assuming that your storyboard name is Main.Storyboard and your SecondViewController Storyboard ID and Restoration ID is also set in Identity Inspector and use Storyboard ID is checked.

enter image description here

like image 31
Rajan Maheshwari Avatar answered Nov 16 '22 15:11

Rajan Maheshwari


If you are starter like me ( both iOS and OSX mechine ) and you wanted to change the entry point within same storyboard, then,

-> long press on the entry point arrow. -> drag it to the view controller you wish to make the starting point, the arrow will now move to your new screen.

like image 34
erluxman Avatar answered Nov 16 '22 14:11

erluxman