Setting the default tab when using storyboards

user1145581 picture user1145581 · Oct 30, 2012 · Viewed 37.3k times · Source

Can anyone please tell me how to set the default tab when using storyboards in iOS. I can't seem to figure out how to accomplish this.

Thank you

Answer

Joshua Finch picture Joshua Finch · Jan 17, 2015

Whilst you can set the initial selected tab programmatically like the other answers, to achieve the same in your storyboard without touching code you would perform the following:

  1. Select the Tab Bar Controller in the Storyboard Interface
  2. Show the Identity Inspector in the Utilities panel
  3. Add a new "User Defined Runtime Attribute"
  4. Set the Key Path to "selectedIndex"
  5. Set the Type to "Number"
  6. Set the Value to the index of the tab you wish to select (a value of 1 would select the second tab for example)
  7. Save the Storyboard, build and run the application

This should be what it looks like when you've achieved the above steps: