2015-07-12 74 views
0

我有一個UIAlertViewController需要一段時間來呈現,並且一會兒它就像一秒鐘左右..代碼如下。UIAlertViewController在實際呈現之前顯示一點延遲

PFUser.logInWithUsernameInBackground(usernameTextField.text!, password:passwordTextField.text!) { 
     (user: PFUser?, error: NSError?) in 
     if user != nil{ 

     self.performSegueWithIdentifier("toMainView", sender: self) 

    } else { 

     let alert = UIAlertController(title: "Error", message: "Entered User Creditinials Are Incorrect. Please Try Again.", preferredStyle: UIAlertControllerStyle.Alert) 

     let action = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) in 

     }) 

     alert.addAction(action) 

     self.presentViewController(alert, animated: true, completion: nil) 
    } 

} 

預先感謝您:)

回答

1

我改變你的代碼一點,現在UIAlertController彈出瞬間。我使用Parse.com錯誤代碼;

PFUser.logInWithUsernameInBackground(usernameTextField.text!, password:passwordTextField.text!) { 
     (user: PFUser?, error: NSError?) -> Void in 
     if user != nil { 
      self.performSegueWithIdentifier("toMainView", sender: self) 
     } else { 
      let ErrorCode = error!.code 
      switch ErrorCode { 
      case 101: 
       let alert = UIAlertController(title: "Error", message: "Entered User Creditinials Are Incorrect. Please Try Again.", preferredStyle: UIAlertControllerStyle.Alert) 
       let action = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler:{ (action: UIAlertAction!) in }) 
       alert.addAction(action) 
       self.presentViewController(alert, animated: true, completion: nil) 
       break 
      default: 
       println(ErrorCode) 
       break 
      } 

     } 
    } 

您可以看到解析錯誤代碼here

+0

沒有工作:/ – Haidous

+0

你的代碼是真的,沒有問題,就像我說的UIAlertController立即彈出我的。您的其他流程是否即時?也許你有互聯網連接問題?有時候解析這個。 –