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
A tab bar controller is a powerful UI component for iOS apps. It's a container view, and you use it to group view controllers together. They give your app's user access to the most important screens of your app.
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:
This should be what it looks like when you've achieved the above steps:
Might seem like overkill for some to subclass UITabBarController
, but, I think it provides the cleanest solution.
BaseTabBarController.swift
Add an @IBInspectable
and set it in viewDidLoad
:
class BaseTabBarController: UITabBarController { @IBInspectable var defaultIndex: Int = 0 override func viewDidLoad() { super.viewDidLoad() selectedIndex = defaultIndex } }
In the storyboard, set you UITabBarController
to be your new subclass:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With