情节提要swift 5中的视图选项卡栏控制器

问题描述 投票:0回答:1

我正在开发swift 5和xcode 11.5

如果用户已登录,我正尝试将其从主故事板移动到选项卡栏控制器,

在我的appDelegate中,我尝试过此操作

    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
    }

这里我要检查是否有用户api_token,如果是,请移至标签栏如果没有显示主故事板但是即使有令牌,它也总是转到main.storyboard!

ios swift storyboard appdelegate swift5
1个回答
0
投票
尝试此代码

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 }

© www.soinside.com 2019 - 2024. All rights reserved.