从故事板 SWIFT 5 查看选项卡栏控制器



我正在研究 swift 5 和 xcode 11.5

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

在我的应用程序中代表我试过这个

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,如果是,请移至选项卡栏 如果没有显示主情节提要 但它总是去主故事板,即使有令牌!

试试这段代码

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
}

最新更新