[英]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).我想从我的 AppDelegate 加载 Tab Bar 控制器(在 Google 成功登录应用程序后)。
I read here how to load a ViewController from AppDelegate我在这里阅读了如何从 AppDelegate 加载 ViewController
Perform Segue from App Delegate swift 从 App Delegate swift 执行 Segue
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.在这个例子中,我的 TabBar 需要一个名称和标识符,据我所知。
Can someone please explain this to me ?有人可以向我解释一下吗? I can't find "identifier" on the Tab Bar Controller , only "Title".我在 Tab Bar Controller 上找不到“标识符”,只有“标题”。
Also, I don't have a navigation controller view in my app.另外,我的应用程序中没有导航控制器视图。
set storyboard ID here在此处设置故事板 ID
and embed the firstViewController in IB in navigationController并将 IB 中的 firstViewController 嵌入到 navigationController 中
let rootViewController = self.window!.rootViewController as! UINavigationController;
rootViewController.pushViewController(viewController, animated: true);
From version.从版本。 iOS 13, The RootViewController will be initiated in scene
function located at SceneDelegate.swift
instead of AppDelegate.swift
file. iOS 13, RootViewController将在位于SceneDelegate.swift
而不是AppDelegate.swift
文件的scene
函数中启动。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.