从AppDelegate加载标签栏控制器

时间:2018-02-10 19:56:21

标签: ios swift xcode uitabbarcontroller 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需要一个名称和标识符。

有人可以向我解释一下吗?我无法在标签栏控制器上找到“标识符”,只能找到“标题”。

另外,我的应用程序中没有导航控制器视图。

2 个答案:

答案 0 :(得分:3)

在这里设置故事板ID

enter image description here 并在navigationController

中嵌入IB中的firstViewController
 let rootViewController = self.window!.rootViewController as! UINavigationController;
 rootViewController.pushViewController(viewController, animated: true);

答案 1 :(得分:0)

iOS 13更新

来自版本。 iOS 13 RootViewController 将在位于以下位置的scene函数中启动  SceneDelegate.swift而非AppDelegate.swift文件。看起来像这样

enter image description here

示例:

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