I'm doing a login for iOS . The problem is that I have 2 viewController
, of which, the first has 2 textField
(username and password) and a button (Enter), and the second, only has a label Ingresaste
and both connected by a Segue
.
The first viewController
has this code:
@IBAction func ingresarButton(_ sender: Any) {
let txtcorreo = correoText.text!
let txtclave = claveText.text!
let url = URL(string: "webservice")
let postString = "txtcorreo=\(txtcorreo)&txtclave=\(txtclave)"
var request = URLRequest(url: url!)
request.httpMethod = "POST"
request.httpBody = postString.data(using: String.Encoding.utf8)
let tarea = URLSession.shared.dataTask(with: request){
(datos, respuesta, error) in
if error != nil{
print(error!)
}else{
do{
let json = try JSONSerialization.jsonObject(with: datos!, options: .mutableContainers) as! [String:Any]
let estado = json["estado"] as! Int
if estado == 200 {
UserDefaults.standard.set(true, forKey: "usuarioLogueado")
UserDefaults.standard.synchronize()
self.performSegue(withIdentifier: "loginSegue", sender: self)
}else{
print("usuario no existe")
self.dismiss(animated: true, completion: nil)
}
}catch{
print("No funciona JSON")
}
}
}
tarea.resume()
}
The problem is that each time the fields are filled erroneously the second viewController
appears for 5 seconds and then returns to the first one.
How can I do so that the second viewController
does not appear when I fill in the wrong fields and only show me a message of User does not exist ?