解析中的 AlertViewController
AlertViewController in Parse
我正在使用 Parse 登录控制器(他们提供的默认 Parse 控制器)为我的应用实现用户 login/pass。它工作正常,我可以登录、注册和完成所有操作。唯一的问题是我想在密码错误时添加一个警报,现在它只在密码错误时打印("Failed to login..."),而用户不知道他们的密码是错误的。我添加了一个警报,但由于某种原因它没有出现。我收到的错误消息是 "Warning: Attempt to present on whose view is not in the window hierarchy!"
这是我添加到代码中的警报:
func logInViewController(logInController: PFLogInViewController!, didFailToLogInWithError error: NSError!) {
println("Failed to login...")
let alertView = UIAlertController(title: "Failed to login...", message: "Incorrect password or username.", preferredStyle: .Alert)
alertView.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil))
presentViewController(alertView, animated: true, completion: nil)
}
我想这可能是因为他们提供的我正在使用的解析默认登录屏幕不在我的故事板上,而是从解析框架调用的(?)。我该如何添加警报视图?
谢谢!
乔希
试试这个
logInController.presentViewController(alertView, animated: true, completion: nil)
我认为当您使用无效凭据登录时,parse 会显示一个警报,所以这可能会显示第二个 - 在警报被解除之后。
我正在使用 Parse 登录控制器(他们提供的默认 Parse 控制器)为我的应用实现用户 login/pass。它工作正常,我可以登录、注册和完成所有操作。唯一的问题是我想在密码错误时添加一个警报,现在它只在密码错误时打印("Failed to login..."),而用户不知道他们的密码是错误的。我添加了一个警报,但由于某种原因它没有出现。我收到的错误消息是 "Warning: Attempt to present on whose view is not in the window hierarchy!"
这是我添加到代码中的警报:
func logInViewController(logInController: PFLogInViewController!, didFailToLogInWithError error: NSError!) {
println("Failed to login...")
let alertView = UIAlertController(title: "Failed to login...", message: "Incorrect password or username.", preferredStyle: .Alert)
alertView.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil))
presentViewController(alertView, animated: true, completion: nil)
}
我想这可能是因为他们提供的我正在使用的解析默认登录屏幕不在我的故事板上,而是从解析框架调用的(?)。我该如何添加警报视图?
谢谢!
乔希
试试这个
logInController.presentViewController(alertView, animated: true, completion: nil)
我认为当您使用无效凭据登录时,parse 会显示一个警报,所以这可能会显示第二个 - 在警报被解除之后。