MathEnthusiast
MathEnthusiast

Reputation: 101

Load Tab Bar Controller from AppDelegate

I have been trying to figure this out by myself, but couldn't.

I want to load a Tab Bar controller from my AppDelegate (After a successful Google Sign in to the application).

I read here how to load a ViewController from AppDelegate

Perform Segue from App Delegate swift

Code in the example:

// Access the storyboard and fetch an instance of the view controller
let storyboard = UIStoryboard(name: "Main", bundle: nil);
let viewController: MainViewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! MainViewController;

// Then push that view controller onto the navigation stack
let rootViewController = self.window!.rootViewController as! UINavigationController;
rootViewController.pushViewController(viewController, animated: true);

In this example, my TabBar needs both a name and identifier, from what I understood.

Can someone please explain this to me ? I can't find "identifier" on the Tab Bar Controller , only "Title".

Also, I don't have a navigation controller view in my app.

Upvotes: 1

Views: 2975

Answers (2)

Surya
Surya

Reputation: 546

iOS 13 Update

From version. iOS 13, The RootViewController will be initiated in scene function located at SceneDelegate.swift instead of AppDelegate.swift file. which looks like this.

enter image description here

Example:

         // Simple init
        let mainSB: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let loggedInTabController = mainSB.instantiateViewController(identifier: "loggedInTabController")
        self.window!.rootViewController = loggedInTabController

Upvotes: 3

Shehata Gamal
Shehata Gamal

Reputation: 100541

set storyboard ID here

enter image description here and embed the firstViewController in IB in navigationController

 let rootViewController = self.window!.rootViewController as! UINavigationController;
 rootViewController.pushViewController(viewController, animated: true);

Upvotes: 3

Related Questions