I'm making a register view on Swift for an app. I want to load a pop-up view when the user is successfully registered to add more data. I'm storing the data using Parse.
I'm using this code to save the data:
@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 {
}
})
}
}
In the else statement, I wanted to add this code:
let vc = (
storyboard?.instantiateViewController(
withIdentifier: "sbPopUpID")
)!
vc.modalTransitionStyle = .crossDissolve
present(vc, animated: true, completion: nil)
But it only works if I load it in after viewDidLoad and didReceiveMemoryWarning, ¿how can I load this Pop Up if there aren't mistakes saving the user data?
Thanks
Your code seems fine, you just forgot to add the implicit self
declaration before some statements (the debugger should advise this to you in default). Try this:
let vc = self.storyboard!.instantiateViewController(withIdentifier: "sbPopUpID")
vc.modalTransitionStyle = .crossDissolve
self.present(vc, animated: true)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.