美文网首页iOS开发
iOS连续present 同一个页面

iOS连续present 同一个页面

作者: 字母大师 | 来源:发表于2018-01-08 18:17 被阅读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];

相关文章

网友评论

    本文标题:iOS连续present 同一个页面

    本文链接:https://www.haomeiwen.com/subject/hnobnxtx.html