1. 程式人生 > >Warning: Attempt to present xx on yy whose view is not in the window hierarchy!

Warning: Attempt to present xx on yy whose view is not in the window hierarchy!

編譯xcode的時候報如下警告:

錯誤程式碼

Warning: Attempt to present xx  on yy  whose view is not in the window hierarchy!

分析

由於呈現模態檢視xx類時,yy檢視的view還沒有被載入到window中。

造成這個原因可能是在yy的viewdidload中呈現xx模態檢視。

解決

把presentModalViewController放到viewDidAppear或者viewWillAppear中