Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: UIAlertController not working in swift

Reyansh Jr.:

I am currently creating a signup page that ask user to fill few specific details such as Name, Country, Email, Password and etc. To make sure user provide all the relevant information I am trying to write a code to send an alert if user does not provide all the information. I have wrote the code taking help from stakeoverflow.

Problem: Whenever user left any field blank it is not showing the alert and by default performing a segue that takes user to signin page. This is the first time I am creating an alert and hence don't what is going wrong (I believe 95% of my code is in place)

can anyone help?


{

@IBAction func signUpPressed(_ sender: Any) {

if (nameText.text?.isEmpty)! || (genderText.text?.isEmpty)! || (countryText.text?.isEmpty)! || (yourSchool.text?.isEmpty)! || (yourSchool.text?.isEmpty)! {

print("Please fill all fields")

//my code is printing above error in the Xcode console but the below code is not working

//setting error message if not all fiels filled
let alertController = UIAlertController(title: "Error", message: "Please fill all fields", preferredStyle: .alert)

let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)

present(alertController, animated: true, completion: nil)

}

else {

Auth.auth().createUser(withEmail: yourEmail.text!, password: yourPassword.text!) { (user, error) in

if error != nil {

///print errror message
let alertController = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)

let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)

self.present(alertController, animated: true, completion: nil)

} else {

print("You have successfully signed up")

self.performSegue(withIdentifier: "JoinUs2SignPage", sender: self)

//updating user information
let userID = Auth.auth().currentUser!.uid
let usertype: String = "Student"
self.ref.child("users").child(userID).setValue(["usertype": usertype ,"username": self.nameText.text!, "usergender": self.genderText.text!, "usercountry": self.countryText.text!, "userschool": self.yourSchool.text!, "userclass": self.yourClass.text!,])
}
}
}

}



}



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: UIAlertController not working in swift

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×