在 IOS 开发当中经常碰到 whose view is not in the window hierarchy 的错误,该错误简单的说,是由于 "ViewController" 还没有被加载,就调用该 ViewController 或者 ViewController 内的方法时,就会报这个错误。
 
在不同地方调用 ViewController,解决的方法也不太一样。
 
 
1. 在 一个 ViewController 里面调用另外一个 ViewController 是出现这个错误:
 
该错误一般是由于在 viewDidLoad 里面调用引起的,解决办法是转移到 viewDidAppear 方法里面
 
 
 
2. 在 AppDelegate.m 中调用遇到这个错误
 
解决办法1:
 
UIViewController *topRootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topRootViewController.presentedViewController)
 {
    topRootViewController = topRootViewController.presentedViewController;
 }
 
//[topRootViewController presentViewController:yourController animated:YES completion:nil];
//or
[topRootViewController myMethod];
 
解决办法2:
 
 UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    LoginViewController* loginViewController = [mainstoryboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
    [self.window makeKeyAndVisible];
//[LoginViewController presentViewController:yourController animated:YES completion:nil];
//or
[LoginViewController myMethod];
 
 
IOS 开发中  Whose view is not in the window hierarchy  错误的解决办法 
原文地址:http://www.cnblogs.com/xunziji/p/4025009.html
 

最新文章

  1. 阿里的weex框架到底是什么
  2. 34-nl 简明笔记
  3. LINUX下 my.cnf php.ini的位置
  4. 线段覆盖4(codevs 3012)
  5. jQuery练习二球队移动
  6. POJ 2886Who Gets the Most Candies?(线段树)
  7. 04、生成 HTMLTestRunner 测试报告
  8. iOS UIKit:CollectionView之布局(2)
  9. Contest 高数题 樹的點分治 樹形DP
  10. jsp 2种include标签的区别
  11. 国内PaaS概述和EEPlat定位
  12. Spark里边:Worker源代码分析和架构
  13. 多线程之线程池Executor应用
  14. 详解SpringMVC请求的时候是如何找到正确的Controller
  15. Laravel 目录结构分析
  16. DevTool开发者工具
  17. JDK8新特性一览
  18. Oracle 动态sql
  19. 执行python文件报错SyntaxError: Non-ASCII character '\xe8' in file, but no encoding declared
  20. Android沉浸式状态栏的简单实现

热门文章

  1. [VijosP1656]萌萌赶考 题解
  2. JavaScript笔试必备语句【转】
  3. CSS居中demo
  4. slf4j的简单介绍
  5. lua中基类和“继承机制”
  6. GeoIP Legacy City数据库安装说明
  7. 初识Windows程序
  8. PHP基础知识之类
  9. 让IE6/IE7/IE8浏览器支持CSS3属性
  10. Mvc form提交