[英]view tab bar controller from storyboard swift 5
I am working on swift 5 and xcode 11.5我正在研究 swift 5 和 xcode 11.5
I am trying to move user from main storyboard to tab bar controller if he is logged in,我正在尝试将用户从主 storyboard 移动到标签栏 controller 如果他已登录,
in my appDelegate I tried this在我的 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
}
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!在这里我想检查是否有用户 api_token,如果是,则移动到标签栏,如果没有,则显示主 storyboard 但它总是转到 main.storyboard,即使有令牌!
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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.