前同事遇到一个问题,说是有个需求需要present同一个页面,发现用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];