【发布时间】:2020-04-25 03:56:15
【问题描述】:
我的应用有问题。场景很简单,成功创建帐户后,我不想关闭当前页面或导航到登录页面。我的故事板如下所示:
成功创建帐户后,我会弹出一个包含一些信息的弹出窗口,我们会向您发送验证电子邮件,在此弹出窗口之后,我想转到左起第二个页面 - 这是我的主应用程序页面(现在称为“视图控制器” )。
我试过关闭窗口,但我在那里没有效果,它只能关闭我的弹出窗口。 当我尝试重定向时,按下后退按钮时出现问题,它会导致注册页面。有一些代码:
// Create new user and send verification email
Auth.auth().createUser(withEmail: userEmail, password: userPassword) { user, error in if error == nil && user != nil {
self.sendVerificationMail();
self.displayAlertMessage(alertTitle: "Success", alertMessage: "Your account created successfully. We send you a verification email.");
// Redirect to View Controller
} else {
self.displayAlertMessage(alertTitle: "Unhandled error", alertMessage: "Undefined error #SignUpViewController_0002");
}
}
...
func displayAlertMessage(alertTitle: String, alertMessage:String, alertRedirection:String = ""){
let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert);
let okAction = UIAlertAction(title:"Ok", style: UIAlertAction.Style.default, handler: nil);
alert.addAction(okAction);
self.present(alert, animated:true, completion:nil);
}
如果我添加这个:
self.view.window!.rootViewController?.dismiss(animated: false, completion: nil)
alert之后只关闭alert,alert之前什么都不做(同dismiss)。
【问题讨论】:
-
您需要为您的确定按钮添加操作
-
@AndresGomes 如果我添加它,我的后退按钮有问题,如果我登录,我应该无法进入注册页面,但如果我按下返回,我会重定向到注册页面
-
nop,当您按下确定按钮时,应用程序将导航到 loginviewcontroller,这很简单,检查您如何使用导航控制器推送视图控制器,当应用程序在 loginviewcontroller 中时,您需要配置后退按钮,如果没有,应用返回 registerviewcontroller
-
@AndreasGomes - self.performSegue(withIdentifier: "test", sender: self); - 我将此添加到确定按钮,按下后我在有效页面上,但我有返回按钮,如果我在注册页面上再次按下它 - 如何避免这种情况?
-
@iSheep - 不要在“确定”按钮操作中使用 performSegue。它将向导航控制器添加更多视图。从当前视图弹出到您需要的视图控制器(主视图)并在警报操作中关闭警报。