从 AppDelegate 加载标签栏控制器
Load Tab Bar Controller from AppDelegate
我一直想自己解决这个问题,但没办法。
我想从我的 AppDelegate 加载一个 Tab Bar 控制器(在成功 Google 登录应用程序后)。
我在这里阅读了如何从 AppDelegate
加载 ViewController
Perform Segue from App Delegate swift
示例中的代码:
// 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);
根据我的理解,在此示例中,我的 TabBar 需要名称和标识符。
有人可以给我解释一下吗?我在 Tab Bar Controller 上找不到 "identifier",只有 "Title".
此外,我的应用中没有导航控制器视图。
在此处设置故事板 ID
并将 firstViewController 嵌入 IB 中的 navigationController
let rootViewController = self.window!.rootViewController as! UINavigationController;
rootViewController.pushViewController(viewController, animated: true);
iOS 13 次更新
来自版本。 iOS 13,
RootViewController 将在位于的 scene
函数中启动
SceneDelegate.swift
而不是 AppDelegate.swift
文件。看起来像这样。
示例:
// Simple init
let mainSB: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let loggedInTabController = mainSB.instantiateViewController(identifier: "loggedInTabController")
self.window!.rootViewController = loggedInTabController
我一直想自己解决这个问题,但没办法。
我想从我的 AppDelegate 加载一个 Tab Bar 控制器(在成功 Google 登录应用程序后)。
我在这里阅读了如何从 AppDelegate
加载 ViewControllerPerform Segue from App Delegate swift
示例中的代码:
// 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);
根据我的理解,在此示例中,我的 TabBar 需要名称和标识符。
有人可以给我解释一下吗?我在 Tab Bar Controller 上找不到 "identifier",只有 "Title".
此外,我的应用中没有导航控制器视图。
在此处设置故事板 ID
let rootViewController = self.window!.rootViewController as! UINavigationController;
rootViewController.pushViewController(viewController, animated: true);
iOS 13 次更新
来自版本。 iOS 13,
RootViewController 将在位于的 scene
函数中启动
SceneDelegate.swift
而不是 AppDelegate.swift
文件。看起来像这样。
示例:
// Simple init
let mainSB: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let loggedInTabController = mainSB.instantiateViewController(identifier: "loggedInTabController")
self.window!.rootViewController = loggedInTabController