从TabBar注销的最佳方式是什么?我有一个应用程序,在其中一个选项卡中连续有一个注销选项。当我选中此行时,我想转到我的登录屏幕。如果您尚未登录,则应用程序会启动登录屏幕,如果您已经是日志杜松子酒,则会启动主屏幕(是标签栏控制器)。我在appDelegate中管理这个:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let defaults = NSUserDefaults.standardUserDefaults()
let notFisrtRun = defaults.boolForKey("notFirstRun")
// Chooses between login view and my list view if the user is already authenticated when the app is launched
if AuthToken.sharedInstance.isAuthenticated() && notFisrtRun {
let tabBarViewController = mainStoryboard.instantiateViewControllerWithIdentifier("TabBarViewController") as? UITabBarController
self.window?.rootViewController = tabBarViewController
} else {
let loginViewController = mainStoryboard.instantiateViewControllerWithIdentifier("LoginViewController") as? LoginViewController
self.window?.rootViewController = loginViewController
}
self.window?.makeKeyAndVisible()
return true
}
答案 0 :(得分:3)
应用程序以模态方式显示登录屏幕是很正常的。退出时,显示else
模式。如果用户重新登录,请关闭loginViewController
。
您还可以创建替换loginViewController
的自定义segue,This question可以帮助您开始使用。