iOS-如何从AppDelegate移除UINavigationController?

时间:2018-08-29 11:21:00

标签: swift uinavigationcontroller uitabbarcontroller

我必须从我的应用中删除UINavigationController,然后添加UITabBarController并保留 我的if statement照常工作。

我的代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    if UserDefaults.standard.value(forKey: "URL") == nil
    {
        let viewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
        let navController = UINavigationController(rootViewController: viewController)
        self.window?.rootViewController = navController
        self.window?.makeKeyAndVisible()

    }else{

        let viewController = storyboard.instantiateViewController(withIdentifier: "ChannelsViewController") as! ChannelsViewController
        let navController = UINavigationController(rootViewController: viewController)
        self.window?.rootViewController = navController
        self.window?.makeKeyAndVisible()
    }

    return true
}

1 个答案:

答案 0 :(得分:0)

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {


let storyboard = UIStoryboard(name: "Main", bundle: nil)

    if UserDefaults .standard .value(forKey: "URL") == nil
    {
        let viewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
        self.window?.rootViewController = viewController
        self.window?.makeKeyAndVisible()

    }else{

        let viewController = storyboard.instantiateViewController(withIdentifier: "ChannelsViewController") as! ChannelsViewController
        self.window?.rootViewController = viewController
        self.window?.makeKeyAndVisible()
    }


    return true
}