【发布时间】:2016-01-25 19:55:23
【问题描述】:
我以前写过这个函数,它工作正常。休息一周后,我再次开始从事该项目,但相同的代码无法正常工作。我在这里错过了什么吗?基本上,如果按下按钮,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)
}
}
}
【问题讨论】:
-
error中有值吗?听起来 Parse 请求可能有问题 -
您能否澄清一下您是否看到了 NSLog 消息?如果不是,则 user == nil 并且您的代码未执行或整个完成处理程序未执行(可能是由于响应错误)。事实上,后者会解释为什么它在一周前可以工作而现在不能工作:)
标签: ios swift uiviewcontroller segue viewcontroller