2015-07-20 61 views
-2

我正在開發一個使用Objective-C的iOS應用程序,我想使用一個Swift類(警報框)。我執行整個功能。沒有任何錯誤,我可以傳遞這些值。不過,我收到以下錯誤消息:Swift的Objective-C:「其視圖不在窗口層次結構中!」錯誤

"whose view is not in the window hierarchy!" 

我已經嘗試了不同的方式:

方法1

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

方法2

self.presentViewController(alertController, animated: true, completion: nil) 

方法3

var mainView:MainViewController = MainViewController() 
mainView.presentViewController(alertController, animated: true, completion: nil) 

所有方法都會產生相同的錯誤消息。

+0

可能重複的[其視圖不在窗口層次結構](http://stackoverflow.com/questions/11862883/whose-view-is-not-in-the-window-hierarchy) –

+0

顯示你爲alertController編碼。 –

回答

0

在我自己,我找到了這個問題的答案。的

UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(alertController,animated: true, completion: nil) 
相關問題