如何解决为什么我无法快速从登录页面移动?
我的应用流程是 1) 如果我使用名称密码注册,那么我需要进入主页,如果我点击注销,我需要进入登录页面 2)注册后,如果我使用注册名和密码登录,我需要转到主页,如果我注销然后转到主页
navigationcontroller(is initial viewcontroller) -> loginpage (login button or registration button) -> homepage
在场景委托中:
func scene(_ scene: UIScene,willConnectTo session: UIScenesession,options connectionoptions: UIScene.Connectionoptions) {
if UserDefaults.standard.bool(forKey: "isLoggedIn") == true{
let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main",bundle: nil)
let vc_Home = mainStoryBoard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
window!.rootViewController = vc_Home
window!.makeKeyAndVisible()
}else{
let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main",bundle: nil)
let vc_Home = mainStoryBoard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
window!.rootViewController = vc_Home
window!.makeKeyAndVisible()
}
guard let _ = (scene as? UIWindowScene) else { return }
}
在我的登录视图控制器中:
@IBAction func loginBtnClicked(_ sender: Any) {
let uName = UserDefaults.standard.string(forKey: "userName")
let uPassword = UserDefaults.standard.string(forKey: "userPassword")
if userNameTextfield.text == uName && passwordTextfield.text == uPassword{
UserDefaults.standard.set(true,forKey: "isLoggedIn")
let storyboard = UIStoryboard(name: "Main",bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
navigationController?.pushViewController(vc,animated: true)
}
else{
showAlert(title: "LogIn",message: "please enter username and password")
}
}
@IBAction func registerBtnClicked(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main",bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "RegisterViewController") as! RegisterViewController
navigationController?.pushViewController(vc,animated: true)
}
@IBAction func registerBtnClicked(_ sender: Any) {
if firstNameTextfield.text?.isEmpty == true{
self.showAlert(title: "Registration",message: "please enter first name")
}
else if lastNameTextfield.text?.isEmpty == true{
self.showAlert(title: "Registration",message: "please enter last name")
}else if emailTextfield.text?.isEmpty == true{
self.showAlert(title: "Registration",message: "please enter email")
}else if passwordTextfield.text?.isEmpty == true{
self.showAlert(title: "Registration",message: "please enter password")
}
else{
let fName = firstNameTextfield.text!
let lName = lastNameTextfield.text!
let userNameReg = fName + " " + lName
UserDefaults.standard.set(userNameReg,forKey: "userName")
UserDefaults.standard.set(lastNameTextfield.text,forKey: "lastName")
UserDefaults.standard.set(emailTextfield.text,forKey: "email")
UserDefaults.standard.set(passwordTextfield.text,forKey: "userPassword")
UserDefaults.standard.set(true,bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "HomeViewController") as! HomeViewController
navigationController?.pushViewController(vc,animated: true)
}
}
}
在主页:
@IBAction func logoutBtnClicked(_ sender: Any) {
UserDefaults.standard.set(false,forKey: "isLoggedIn")
self.navigationController?.popViewController(animated: true)
}
在这里,如果我点击 loginBtn 或 registrationBtn 我无法从登录页面移动,为什么我无法移动?
请帮忙写代码
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。