美文网首页iOS开发笔记
解决“whose view is not in the wind

解决“whose view is not in the wind

作者: ship1912 | 来源:发表于2017-01-17 10:49 被阅读664次

在iOS 中弹窗时有时会失败,打印下面的错误信息

Warning: Attempt to present on whose view is not in the window hierarchy!

调用方法是

[self presentViewController:secondView animated:YES completion:nil];

原因是因为self有可能不是顶层窗口,改用下面的方式调用

UIViewController * top= [UIApplicationsharedApplication].keyWindow.rootViewController;
[top presentViewController:secondView animated:YES completion:nil];

用上面的代码有时还是不能解决,最终改用下面的代码

-(UIViewController *) topMostController {
  UIViewController*topController = [UIApplicationsharedApplication].keyWindow.rootViewController;
  while(topController.presentedViewController){
    topController=topController.presentedViewController;
  }
  returntopController;
}

UIViewController * top = [self topMostController];
[top presentViewController:secondView animated:YES completion:nil];

相关文章

  • 解决“whose view is not in the wind

    在iOS 中弹窗时有时会失败,打印下面的错误信息 调用方法是 原因是因为self有可能不是顶层窗口,改用下面的方式...

  • 2018-07-05

    关于whose view is not in the window hierarchy错误的解决方法

  • Moonlit night

    Black night The wind blows through Whose eyes are lost? T...

  • whose view is not in the window

    这是最近在做强制更新的小功能时 碰见的三个小警告⚠️ 简述一下解决的思路 你遇见的场景可能与此并不雷同 所以仅供参...

  • whose view is not in the window

    新到的公司,要求马上改BUG,ios11跳转相机崩溃,于是我添加了隐私权限,还是出现UI界面错乱问题,还有提示上面...

  • whose view is not in the window

    UIViewController *topRootViewController = [[UIApplication...

  • whose view is not in the window

    今天在调用播放视频控件的时候,当MPMoviePlayerViewController 成功读取 url Link...

  • whose view is not in the window

    最近在做项目时遇到这样的一个问题,工程里有三个A , B , C三个页面.由于项目需求需要,需从A页面presen...

  • whose view is not in the window

    项目突然抽风, 原本第三方登陆后返回的界面不显示了,源代码这里明明model出控制器了, 最后发现控制台打印: w...

  • whose view is not in the window

    写代码的时候在viewdidload里面做了个判断,如果判断为否,则弹出一个alert,可是莫名其妙地出现一个警...

网友评论

本文标题:解决“whose view is not in the wind

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