您好我有一个登录视图控制器和我的应用程序故事板视图。初始视图控制器指向应用程序仪表板。如果用户登录,我正在检查我的appDelegate应用程序功能。之后我(重新)设置正确的UIViewController作为初始。不知怎的,应用程序总是进入初始视图控制器,然后说oops我需要登录,因为用户没有登录...我怎么能避免这种情况?
这是我目前的代码。
dispatch_async(dispatch_get_main_queue(), {
let storyboard: UIStoryboard = UIStoryboard.init(name: "Main", bundle: nil)
if (settings.isLoggedIn())
{
let vc: AnyObject! = storyboard.instantiateInitialViewController()
self.window?.rootViewController = vc as? UIViewController
} else {
let vc: AnyObject! = storyboard.instantiateViewControllerWithIdentifier("login")
self.window?.rootViewController = vc as? UIViewController
}
})
答案 0 :(得分:0)
如何在appdelegate
中检查以下方法中登录的用户func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
//check user logged or not, if true you can set the initial view controller given below
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc : UIViewController! = storyboard.instantiateViewControllerWithIdentifier("urcontroller")
let window = UIApplication.sharedApplication().windows[0] ;
window.rootViewController = vc;
return true
}