Reputation: 101
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
Reputation: 546
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
Upvotes: 3
Reputation: 100541
set storyboard ID here
and embed the firstViewController in IB in navigationController
let rootViewController = self.window!.rootViewController as! UINavigationController;
rootViewController.pushViewController(viewController, animated: true);
Upvotes: 3