简体   繁体   中英

view tab bar controller from storyboard swift 5

I am working on swift 5 and xcode 11.5

I am trying to move user from main storyboard to tab bar controller if he is logged in,

in my appDelegate I tried this

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

    if let api_token = helper.getApiToken() {
        print("api_token: \(api_token)")

        let tab = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: "maintab")
        window?.rootViewController = tab
    }
    return true
}

here I want to check if there is a user api_token, if yes move to the tab bar if no show the main storyboard but it always goes to main.storyboard even if there is a token!

Try this code

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

    if let api_token = helper.getApiToken() {
        print("api_token: \(api_token)")

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let tab = storyboard.instantiateViewController(withIdentifier: "maintab")
        window?.rootViewController = tab
    }

    return true
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM