使用swift

时间:2016-01-25 00:12:27

标签: switch-statement viewcontroller

我之前写过这个函数,它运行正常。经过一周的休息后,我再次开始研究该项目,同样的代码无效。我在这里错过了什么吗?基本上,如果按下按钮,checkCredentials将运行。 “else”部分中的所有内容都完全正常,但“if user!= nil”部分无效:

    func checkCredentials (){
    PFUser.logInWithUsernameInBackground(usernameLoginTxt.text!, password: passwordLoginTxt.text!){
        (user:PFUser?, error:NSError?) -> Void in
        if user != nil{


            let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let vc: UIViewController = storyboard.instantiateViewControllerWithIdentifier("SearchViewController") as UIViewController
            self.presentViewController(vc, animated: false, completion:nil)
            NSLog("it was successfull dude")

        }else{

            let title = "Warning!"
            let message = "You have entered the wrong username or password.\n Please try again!"
            let okButton = "Ok"
            let alert = UIAlertController(title: title, message: message, preferredStyle:  UIAlertControllerStyle.Alert)
            let okayButton = UIAlertAction(title: okButton, style:  UIAlertActionStyle.Cancel, handler:  nil)
            alert.addAction(okayButton)

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


        }
    }

}

0 个答案:

没有答案