Swift:如何实现登录故事板?

时间:2015-01-27 13:31:20

标签: swift login storyboard

我有两个不同的故事板:

  • Mainstoryboard:SWrevealViewController(应用程序的主要部分)
  • Loginstoryboard:登录/注册控制器

当用户未登录或用户退出时,应使用Loginstoryboard。那么主板应该有一个segue。

我怎样才能在swift中实现它?

期待您的回答!

1 个答案:

答案 0 :(得分:7)

您是否尝试在rootViewController

中切换application(_:didFinishLaunchingWithOptions:)

假设MainstoryboardrootViewController

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
}