前同事遇到一個問題,說是有個需求需要present同一個頁面妹萨,發(fā)現用self,出現whose view is not in the window hierarchy! 錯誤
就是視圖不在窗口層次!因為我們present是用的是root視圖控制器操作的
所以
//需要present的頁面
PresentViewController *p = [PresentViewController new];
//給個隨機色
p.view.backgroundColor =randomColor;
UIViewController *rootViewController = [[UIApplication sharedApplication] keyWindow].rootViewController;
while (rootViewController.presentedViewController)
{
rootViewController = rootViewController.presentedViewController;
}
[rootViewController presentViewController:p animated:YES completion:nil];