zoukankan      html  css  js  c++  java
  • IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法

    在 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
     
  • 相关阅读:
    thinkphp中的验证码的实现
    js深入研究之牛逼的类封装设计
    js深入研究之函数内的函数
    js深入研究之初始化验证
    js深入研究之Person类案例
    js深入研究之匿名函数
    js深入研究之类定义与使用
    sublime text3 自动编译php 适合用于简单的php文件执行
    PHP实现四种基本排序算法 得多消化消化
    thinkphp中的类库与引用import引入机制
  • 原文地址:https://www.cnblogs.com/xunziji/p/4025009.html
Copyright © 2011-2022 走看看