简体   繁体   English

从 AppDelegate 加载标签栏控制器

[英]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);

iOS 13 Update iOS 13 更新

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.

相关问题 从AppDelegate和Tab Bar推送View Controller - Push View Controller From AppDelegate and Tab Bar 无法从AppDelegate推送到View Controller而不会丢失导航栏和标签栏设置iOS - Can't push to View Controller from AppDelegate without losing Navigation Bar and Tab Bar setup iOS 从我的AppDelegate到视图控制器的Segue删除了我的UI标签栏 - Segue to a View Controller from my AppDelegate removes my UI Tab Bar AppDelegate中的iOS初始化选项卡栏控制器视图控制器 - iOS Init Tab Bar Controller View Controllers in AppDelegate 在Swift中从AppDelegate加载嵌入到UINavigationController的控制器 - Load a controller embed to a UINavigationController from AppDelegate in Swift AppDelegate当根控制器为标签栏控制器时如何定位导航控制器 - AppDelegate how to target navigation controller when root controller is tab bar controller 在AppDelegate iOS中自定义标签栏 - Customize Tab Bar in AppDelegate iOS 显示当前标签栏控制器中的另一个标签栏控制器 - Show another Tab Bar Controller From Current Tab Bar Controller 从Tab Bar Controller推到新的Tab Bar Controller - Push from Tab Bar Controller to a new Tab Bar Controller 是否可以从标签栏控制器导航到另一个标签栏控制器? - Is it possible to navigate from a tab bar controller to another tab bar controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM