ios - Adding an alert to login screen Swift -


for reason i'm having trouble adding alert sign in screen when user gets password , username wrong. far have alert when there 1 text field filled in when click sign in button if both text fields populated no alert shows. can me that?

@ibaction func loginbuttontapped(sender: anyobject) {     if (self.useremailtextfield.text == "" || self.userpasswordtextfield.text == "") {         var alert = uialertview()         alert.title = "sign in error"         alert.message = "you must enter username , password"         alert.addbuttonwithtitle("dismiss")         alert.show()         return;     }      func checklogin(username: string, password: string ) -> bool {         if ((username == useremailtextfield) && (password == userpasswordtextfield)) {             return true         } else {             return false         }     }      if (checklogin(self.useremailtextfield.text, self.userpasswordtextfield.text)) {         self.performseguewithidentifier("dismisslogin", sender: self)     } else {     } 

i suggest use isempty property of texts , should use uialertcontroller in swift

@ibaction func sendlogin() {     self.view.endediting(true)      if txtpassword.text.isempty || txtpassword.text.isempty     {         let alert = uialertcontroller(             title: "invalid login",             message: "please fill user , password",             preferredstyle: uialertcontrollerstyle.alert)          let okaction = uialertaction(title: "ok", style: .default) { (action) in              // when user press ok button, deleting text in both fields or nothing         }          alert.addaction(okaction)          presentviewcontroller(alert, animated: true, completion: nil)         return     }      // login authentication process } 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -