2015-10-29 102 views
1

我想显示UIAlertView当登录凭据是错误的,而是它只是转到下一个视图,并且不显示UIAlertView?UIAlertController无法显示UIAlertView中

它说无效的登录凭据,但似乎忽略错误。我尝试了一个自定义的继续,但它在按下按钮时自动调用。我没有没有self.presentsegue所以它是代码。如果可达性不是问题,只要检查用户是否连接到互联网,那不是问题。

func login() 
{ 

    if Reachability.isConnectedToNetwork() 
    { 
     activityLoader.alpha = 1 
     activityLoader.startAnimating() 
     let emailText = EmailTextBox.text 

     PFUser.logInWithUsernameInBackground(EmailTextBox.text!, password: PasswordTextBox.text!){(user: PFUser?, error: NSError?) -> Void in 
      if user != nil 
      { 
       //Login Successfully 
       NSUserDefaults.standardUserDefaults().setObject(emailText, forKey: "UserSaved") 
       NSUserDefaults.standardUserDefaults().synchronize() 

       self.activityLoader.alpha = 0 
       self.activityLoader.stopAnimating() 


       let title = "Successfully logged in" 
       let message = "Enjoy" 
       let okText = "OK" 

       let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert) 
       let OKbutton = UIAlertAction(title: okText, style: UIAlertActionStyle.Cancel, handler: nil) 
       alert.addAction(OKbutton) 
       self.presentViewController(alert, animated: true, completion: nil) 


      } 
      else 
      { 
       self.activityLoader.alpha = 0 
       self.activityLoader.stopAnimating() 

       let title = "Please try again" 
       let message = "Check your login credentials" 
       let okText = "OK" 

       let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert) 
       let OKbutton = UIAlertAction(title: okText, style: UIAlertActionStyle.Cancel, handler: nil) 
       alert.addAction(OKbutton) 
       self.presentViewController(alert, animated: true, completion: nil) 

      } 
     } 
    } 
    else 
    { 
     self.activityLoader.alpha = 0 
     self.activityLoader.stopAnimating() 

     let title = "No Internet Connection" 
     let message = "Please ensure you are connected to the Internet" 
     let okText = "OK" 

     let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert) 
     let OKbutton = UIAlertAction(title: okText, style: UIAlertActionStyle.Cancel, handler: nil) 
     alert.addAction(OKbutton) 
     self.presentViewController(alert, animated: true, completion: nil) 


    } 


} 


@IBAction func LogInPressed(sender: AnyObject) 
{ 

    if self.EmailTextBox.text == "" || self.PasswordTextBox.text == "" 
    { 
     let title = "Please try again" 
     let message = "Check your login credentials" 
     let okText = "OK" 

     let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert) 
     let OKbutton = UIAlertAction(title: okText, style: UIAlertActionStyle.Cancel, handler: nil) 
     alert.addAction(OKbutton) 
     self.presentViewController(alert, animated: true, completion: nil) 
    } 

    else 
    { 
     login() 
    } 
} 
+0

“*它说无效登录凭据,但似乎忽略错误。*”它说“无效登录凭据”在哪里?该字符串不会出现在您的程序中。另外,“错误”是什么意思? – kdbanman

+0

“*我没有'self.presentsegue'所以它是代码。*”这是**非常难以理解。你能澄清吗? – kdbanman

+0

“*如果可达性不是问题,只要检查用户是否连接到互联网,那就不是问题。*”这也很难理解。你能澄清一下吗? – kdbanman

回答

0

检查在您的故事板文件中看到从按钮到下一个视图控制器没有延续。