Parse Log In Error不会弹出

时间:2015-08-24 03:09:21

标签: ios swift parse-platform

我正在使用Parse使用Swift开发iPhone应用程序。 我使用Parse的PFLoginViewController创建了一个简单的登录屏幕。当用户执行注册而没有用户名等操作时,会出现弹出窗口(UIAlertControllers),但是当登录凭据无效时,没有弹出窗口。相反,我只是在控制台中出错:

2015-08-23 22:50:10.246 SwifferApp[24429:1614072] [Error]: invalid login parameters (Code: 101, Version: 1.8.1)

我有一个函数用于登录失败,但我不能通过PFLoginViewController呈现UIAlertController

 func logInViewController(logInController: PFLogInViewController, didFailToLogInWithError: NSError?){

        var invalidCredentials = UIAlertController(title: "Invalid Credentials", message: "Incorrect username or password.", preferredStyle: UIAlertControllerStyle.Alert)

        invalidCredentials.addAction(UIAlertAction(title: "Okay", style: .Default, handler: { (action: UIAlertAction!) in
            //do nothing
        }))

        presentViewController(invalidCredentials, animated: true, completion: nil)
    }

在“presentViewController”的行上,我收到了错误

2015-08-23 22:50:10.249 SwifferApp[24429:1613783] Warning: Attempt to present <UIAlertController: 0x7c1f1a50> on <SwifferApp.TimelineTableViewController: 0x7c1b7120> whose view is not in the window hierarchy!

我可以做些什么来包含登录错误弹出窗口?

2 个答案:

答案 0 :(得分:0)

错误描述了原因本身。

  

警告:尝试出现    谁的观点不是   在窗口层次结构中!

您的TimelineTableViewController不在视图层次结构中。这就是警报没有出现的原因。如果您仍想显示警告不在TimelineTableViewController,那么,

替换它:

presentViewController(invalidCredentials, animated: true, completion: nil)

有了这个:

UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(invalidCredentials, animated: true, completion: nil)

希望这有助于......:)

答案 1 :(得分:0)

想出来了!

我需要做的就是替换

presentViewController(invalidCredentials, animated: true, completion: nil)

logInViewController.presentViewController(invalidCredentials, animated: true, completion: nil)