我想将您的想法复制到我通常在以下示例中所做的事情中。
这就是我的故事板的样子:
正如您所看到的,登录/注册和选项卡栏未与任何类型的 Segue 连接。
这里登录导航控制器是初始控制器的设置。
为该导航控制器分配 Storyboard ID(例如登录导航):
对选项卡栏控制器执行相同操作,分配 Storyboard ID(例如主页标签栏)
现在,您只需在登录导航和选项卡栏之间移动应用程序的根视图控制器即可。
因此,如果用户成功登录,则将应用程序的根视图更改为主页标签栏使用以下代码:
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let home: UITabBarController = storyboard.instantiateViewControllerWithIdentifier("HomeTabBar") as! UITabBarController
appDelegate.window?.rootViewController = home
当用户登录时,再次将根视图更改为登录导航:
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let entryPoint:UIViewController = mainStoryboard.instantiateViewControllerWithIdentifier("LoginNavigation")
appDelegate.window?.rootViewController = entryPoint
The appDelegate
定义在我的constants.swift
file :
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate