2015-08-24 52 views
0

我正在开发一个使用解析的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

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) 
    } 

呈现UIAlertController在与线“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! 

我能做些什么来包括登录错误弹出?

回答

0

想通了!

所有我需要做的是更换

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

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

错误描述了原因本身。

警告:试图提出有关 谁的观点是不是在窗口层次 !

您的TimelineTableViewController不在视图层次结构中。这就是为什么警报没有显示出来。如果你想仍然显示在TimelineTableViewController则不是警报,

替换此:

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

有了这个:

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

希望这有助于... :)

+0

我还是得到了同样的错误:(我知道它不是在窗口层次原因解析登录屏幕是当前存在,但我不知道如何在解析日志屏幕上显示UIAlert –