Anh73
Anh73

Reputation: 85

How to change the initial view controller of storyboard?

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!

Upvotes: 7

Views: 11412

Answers (3)

erluxman
erluxman

Reputation: 19385

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.

Upvotes: 1

Rajan Maheshwari
Rajan Maheshwari

Reputation: 14571

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

Upvotes: 1

Surya Subenthiran
Surya Subenthiran

Reputation: 2217

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

enter image description here

Upvotes: 13

Related Questions