简体   繁体   中英

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.

set storyboard ID here

在此处输入图片说明 and embed the firstViewController in IB in navigationController

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

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.

在此处输入图片说明

Example:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM