Set default Tab in TabBar App

How can I set “Default” tab wich user will see at the first launching of my App?
xCode default selection is the first ViewController but I want to change it to third.

Well technically the launch screen is the first thing the user will see.

I didn’t mean to change LaunchScreen. I want to change the default ViewController user see when open the app.

You could create a subclass of UITabBarController. In the viewDidLoad method, set the selectedIndex property to the desired tab. The index starts at 0, so setting it to 2 would mean your 3rd tab is the first to display. You’ll then need to change the class of the tab bar controller in your storyboard to your new class.

Here is what I tried. Worked great to show the 2nd tab (index = 1).

MyTabBarController.swift
import UIKit

class MyTabBarController: UITabBarController {
  
  override func viewDidLoad() {
    super.viewDidLoad()
    self.selectedIndex = 1
  }
}

Have fun!

3 Likes