iOS开发

iOS连续present 同一个页面

2018-01-08  本文已影响253人  字母大师

前同事遇到一个问题,说是有个需求需要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];
上一篇 下一篇

猜你喜欢

热点阅读