2015-08-24 50 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 –