我有两个不同的故事板:
当用户未登录或用户退出时,应使用Loginstoryboard。那么主板应该有一个segue。
我怎样才能在swift中实现它?
期待您的回答!
扬
答案 0 :(得分:7)
您是否尝试在rootViewController
application(_:didFinishLaunchingWithOptions:)
假设Mainstoryboard
有rootViewController
:
if userIsNotLoggedIn {
let storyboard = UIStoryboard(name: "Loginstoryboard", bundle: nil)
let loginController = storyboard.instantiateViewControllerWithIdentifier("LoginNavigationController") as UINavigationController
window?.rootViewController = loginController
}
要在登录后切换视图控制器,您可以执行以下操作:
func loggedIn() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let mainController = storyboard.instantiateViewControllerWithIdentifier("MainVC") as UIViewController
let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
appDelegate.window?.rootViewController = mainController
}