在做界面跳轉(zhuǎn)的時(shí)候,我們經(jīng)常會(huì)用到這兩個(gè)函數(shù)
func dismissViewControllerAnimated(flag:Bool, completion: (() ->Void)?)
func presentViewController(viewControllerToPresent:UIViewController, animated flag:Bool, completion: (() ->Void)?)
有時(shí)候先把自己所在的這個(gè)頁(yè)面 dismiss 掉,再 present 另外一個(gè)頁(yè)面時(shí)照皆,控制臺(tái)會(huì)提示?whose view is not in the window hierarchy 這個(gè)錯(cuò)誤信息。
解決方法:
①如果這兩個(gè)語(yǔ)句出現(xiàn)按鈕點(diǎn)擊事件里面
這時(shí)只要把 dismiss 這一句注釋掉,直接 present 就可以啦典阵。
②而如果這種語(yǔ)句出現(xiàn)在 ViewDidLoad 方法中
那么則應(yīng)該把語(yǔ)句轉(zhuǎn)移到 ViewDidAppear 方法中,畢竟你不能對(duì)一個(gè)只 Load 完畢镊逝,卻還沒(méi)有 Appear 出來(lái)的 ViewController 要求太多 :)
部分參考自StackOverFlow中的:whose view is not in the window hierarchy