我正在处理应用程序,其注销功能无法正常工作。 here is image of storyborad
所以我的问题是启动应用程序并注销后可以正常工作,但是当我关闭其最近的标签并再次尝试注销时,该屏幕不会返回登录屏幕。
这是我的注销代码
@IBAction func onClickLogOut(_ sender: Any)
{
do
{
try Auth.auth().signOut()
UserDefaults.standard.set(false, forKey: "isLogin")
UserDefaults.standard.removeObject(forKey: "uid")
UserDefaults.standard.removeObject(forKey: "email")
UserDefaults.standard.synchronize()
}
catch let err
{
print(err.localizedDescription)
}
let appDel = UIApplication.shared.delegate as! AppDelegate
let st = UIStoryboard(name: "Main", bundle: Bundle.main)
let vc = st.instantiateViewController(identifier: "LoginSignUpVC") as? LoginSignUpVC
let navVc = UINavigationController(rootViewController: vc!)
appDel.window?.rootViewController = navVc
appDel.window?.makeKeyAndVisible()
self.parent?.navigationController?.popToRootViewController(animated: true)
}
答案 0 :(得分:0)
我不确定close its recent tab
是什么意思?
确定活动与您的演示页面上的注销按钮相关联吗?
我认为这里不需要调用window.makeKeyAndVisible
和navigationController.popToRootViewController
。
我将编写重定向逻辑如下:
@IBAction func onClickLogOut(_ sender: Any)
{
do
{
try Auth.auth().signOut()
UserDefaults.standard.set(false, forKey: "isLogin")
UserDefaults.standard.removeObject(forKey: "uid")
UserDefaults.standard.removeObject(forKey: "email")
UserDefaults.standard.synchronize()
}
catch let err
{
print(err.localizedDescription)
}
guard let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginSignUpVC") as? LoginSignUpVC else {
print("Error: VC not found")
return
}
UIApplication.shared.keyWindow?.rootViewController = vc
}
答案 1 :(得分:0)
let appDel = UIApplication.shared.delegate as! AppDelegate
let st = UIStoryboard(name: "Main", bundle: Bundle.main)
let vc = st.instantiateViewController(identifier: "LoginSignUpVC") as? LoginSignUpVC
let navVc = UINavigationController(rootViewController: vc!)
appDel.window?.rootViewController = navVc
appDel.window?.makeKeyAndVisible()
在上面的代码中,您将创建 LoginSignUpVC 的新实例和导航控制器,并将此实例设置为根视图控制器,从而取消分配先前设置的根视图控制器。因此,不需要popToRootViewController。
答案 2 :(得分:0)
将rootviewcontroller设置为popToRootViewController
后,为什么要进行LoginSignUpVC
?
这不是必需的,因为您已经将rootviewcontroller设置为LoginSignUpVC.
只需从代码中删除popToRootViewController
行即可。
@IBAction func onClickLogOut(_ sender: Any) {
do {
try Auth.auth().signOut()
UserDefaults.standard.set(false, forKey: "isLogin")
UserDefaults.standard.removeObject(forKey: "uid")
UserDefaults.standard.removeObject(forKey: "email")
UserDefaults.standard.synchronize()
}
catch let err {
print(err.localizedDescription)
}
let appDel = UIApplication.shared.delegate as! AppDelegate
let st = UIStoryboard(name: "Main", bundle: Bundle.main)
let vc = st.instantiateViewController(identifier: "LoginSignUpVC") as? LoginSignUpVC
let navVc = UINavigationController(rootViewController: vc!)
appDel.window?.rootViewController = navVc
}
我希望它对您有用!