您好我的英语不是很好,我提前道歉。
我的申请有问题。场景如下我将rootViewController分配给我的ViewController控制器,这是我的开始。我有其他屏幕,这是一个描述屏幕,我有两个登录和注册按钮,当预装时我带到他们的控制器。
现在,当我在日志全屏窗体上时,我发送解雇顺序:
ViewController注册
self.dismiss(animated: false, completion: nil)
一切都好,视图是隐藏的,但是当进入上一个屏幕时,如果有解雇顺序,如果已经有用户,我会进行验证:
ViewController说明App
self.dismiss(animated: false, completion: nil)
但它没有执行动作。
代码
的UIViewController
class ViewController: UIViewController {
override func viewDidLoad() {
FIRAuth.auth()!.addStateDidChangeListener() { auth, user in
if user == nil {
let descriptionController = DescriptionController()
present(descriptionController, animated: true, completion: nil)
}
}
}
}
DescriptionController
class DescriptionController: UIViewController {
@IBOutlet weak var sign_in_custom: UIButton!
override func viewDidLoad() {
FIRAuth.auth()!.addStateDidChangeListener() { auth, user in
if user != nil {
self.dismiss(animated: false, completion: nil)
}
}
sign_in_custom.addTarget(self, action: #selector(changeToSingIn), for: [.touchUpInside])
}
func changeToSingIn() {
let singInController = SingInController()
present(singInController, animated: true, completion: nil)
}
}
SingInController
class SingInController: UIViewController {
@IBOutlet weak var sign_in_custom: UIButton!
override func viewDidLoad() {
sign_in_custom.addTarget(self, action: #selector(singIn), for: [.touchUpInside])
}
func showLoad() {
let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .alert)
alert.view.tintColor = UIColor.black
let loadingIndicator: UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(10, 5, 50, 50) ) as UIActivityIndicatorView
loadingIndicator.hidesWhenStopped = true
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
loadingIndicator.startAnimating();
alert.view.addSubview(loadingIndicator)
present(alert, animated: true, completion: nil)
}
func hideLoad() {
self.dismiss(animated: false, completion: nil)
}
func singIn() {
if (emailVarification()){
if (passwordVarification()){
showLoad()
guard let email = emailTextField.text else { return }
guard let password = passwordTextField.text else { return }
FIRAuth.auth()?.createUser(withEmail: email, password: password) { (user, error) in
hideLoad()
if (user != nil) {
self.dismiss(animated: false, completion: nil)
} else {
let alert = UIAlertController(title: "Error", message: "This is a error", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
} else {
let alert = UIAlertController(title: "Error", message: "This is a error", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
} else {
let alert = UIAlertController(title: "Error", message: "This is a error", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}
答案 0 :(得分:1)
在 ViewdidAppear :
中使用此代码FIRAuth.auth()!.addStateDidChangeListener() { auth, user in
if user != nil {
self.dismiss(animated: false, completion: nil)
}
}
sign_in_custom.addTarget(self, action: #selector(changeToSingIn), for: [.touchUpInside])
答案 1 :(得分:0)
不是让DescriptionController自行解散,而是更好的方法是通知ViewController用户已登录并在必要时返回任何错误。然后,ViewController可以根据成功或失败的登录执行所需的任何其他步骤。这可以通过使用委托模式来实现(DescriptionController定义协议,ViewController实现它)。
答案 2 :(得分:0)
这是因为第二个控制器基本上只放在现有控制器的顶部。第一个视图仍然在第二个视图下运行,当第二个视图被解除时,第一个视图将不会调用ViewDidLoad。因此,要解决它,您可能希望将其添加到ViewDidAppear函数中。