在解析(SWIFT)上保存数据时打开弹出视图
问题描述:
我正在Swift上为一个应用程序创建一个注册视图。我想在用户成功注册时加载弹出视图以添加更多数据。我正在使用Parse存储数据。在解析(SWIFT)上保存数据时打开弹出视图
我使用这个代码来保存数据:
@IBAction func registerButtonPressed(_ sender: Any) {
if emailTextField.text == "" || usuerTextField.text == "" || password1TextField.text == "" || password2TextField.text == "" {
createAlert(title: "Error", message: "Fill all data")
} else {
if password1TextField.text != password2TextField.text {
createAlert(title: "Error", message: "Passwords must be the same")
} else {
activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
activityIndicator.center = self.view.center
activityIndicator.hidesWhenStopped = true
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
view.addSubview(activityIndicator)
activityIndicator.startAnimating()
UIApplication.shared.beginIgnoringInteractionEvents() // UIApplication.shared() is now UIApplication.shared
let user = PFUser()
user.username = usuerTextField.text
user.email = emailTextField.text
user.password = password1TextField.text
let acl = PFACL()
acl.getPublicWriteAccess = true
user.acl = acl
user.signUpInBackground(block: { (success, error) in
self.activityIndicator.stopAnimating()
UIApplication.shared.endIgnoringInteractionEvents() // UIApplication.shared() is now UIApplication.shared
if error != nil {
var displayErrorMessage = "Please try again later."
let error = error as NSError?
if let errorMessage = error?.userInfo["error"] as? String {
displayErrorMessage = errorMessage
}
self.createAlert(title: "Signup Error", message: displayErrorMessage)
} else {
}
})
}
}
else语句,我想添加以下代码:
let vc = (
storyboard?.instantiateViewController(
withIdentifier: "sbPopUpID")
)!
vc.modalTransitionStyle = .crossDissolve
present(vc, animated: true, completion: nil)
但如果我加载它在它只能在viewDidLoad和didReceiveMemoryWarning之后,如果在保存用户数据时没有错误,我该如何加载这个弹出窗口?
感谢
答
您的代码似乎罚款,你忘记了一些语句(调试器应在默认情况下告知给你)前添加隐self
声明。试试这个:
let vc = self.storyboard!.instantiateViewController(withIdentifier: "sbPopUpID")
vc.modalTransitionStyle = .crossDissolve
self.present(vc, animated: true)