一尘不染

Swift:如何实现登录情节提要?

swift

我有两个不同的故事板:

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

当用户未登录或注销时,应使用Loginstoryboard。然后应该对Mainstoryboard进行设置。

如何迅速实施?

期待您的回答!
一月


阅读 226

收藏
2020-07-07

共1个答案

一尘不染

您是否尝试切换您rootViewControllerapplication(_: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
}
2020-07-07