我使用firebase进行身份验证。一旦用户登录,我想用Tab控制器移动到主屏幕。
App委托功能
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.makeKeyAndVisible()
navToSignin()
return true
}
func navToHome()
{
print("navToHome")
let customTab = CustomTabBar()
window?.rootViewController = customTab
}
func navToSignin()
{
let firstPage = SigninNewVC()
window?.rootViewController = firstPage
}
SigninNewVC
override func viewWillAppear(animated: Bool)
{
super.viewWillAppear(animated)
if FIRAuth.auth()?.currentUser?.uid != nil
{
if let appDel = UIApplication.sharedApplication().delegate as? AppDelegate
{
print("viewWillAppear")
appDel.navToHome()
//This func gets called but still does not navigate to Home VC
}
}
}
private func fbSignin(token: String)
{
FIRAuth.auth()?.signInWithCustomToken(token) { (user, error) in
if error == nil
{
if user != nil
{
if let appDel = UIApplication.sharedApplication().delegate as? AppDelegate
{
JulehHUD.hideProgressHUD(self.view!)
appDel.jumpToHome()
//This part works fine when i login it navigates to Home Screen
}
}
}
else
{
print("Error:\n\(error)\n")
}
}
}
当我第一次登录时,它可以正常工作,我可以导航到主屏幕。但如果我重新启动应用程序我无法导航到主屏幕。它通过打印语句打印(“viewWillAppear”)和&amp ;;保留在SigninNewVC中。 print(“navToHome”)被执行。不知道我做错了什么。以下是我的Tab栏类
class CustomTabBar:UITabBarController {
override func viewDidLoad()
{
super.viewDidLoad()
let homeController = HomeScreenVC()
let newHomeTab = UINavigationController(rootViewController: homeController)
newHomeTab.title = "Home"
viewControllers = [newHomeTab]
}
}
请让我知道我做错了什么。
答案 0 :(得分:0)
我认为你错误地透露了VC,你应该使用类似CustomTabBar(nibName: nil, bundle:nil)
的内容并在其中添加你的子视图loadView:
答案 1 :(得分:0)
将以下代码添加到navToHome()& App Delegate中的navToSignin()修复了该问题。
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.makeKeyAndVisible()