IOS 开发中 Whose view is not in the window hierarchy 错误的解决办法
2024-10-14 05:36:02
在 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
原文地址:http://www.cnblogs.com/xunziji/p/4025009.html
最新文章
- 阿里的weex框架到底是什么
- 34-nl 简明笔记
- LINUX下 my.cnf php.ini的位置
- 线段覆盖4(codevs 3012)
- jQuery练习二球队移动
- POJ 2886Who Gets the Most Candies?(线段树)
- 04、生成 HTMLTestRunner 测试报告
- iOS UIKit:CollectionView之布局(2)
- Contest 高数题 樹的點分治 樹形DP
- jsp 2种include标签的区别
- 国内PaaS概述和EEPlat定位
- Spark里边:Worker源代码分析和架构
- 多线程之线程池Executor应用
- 详解SpringMVC请求的时候是如何找到正确的Controller
- Laravel 目录结构分析
- DevTool开发者工具
- JDK8新特性一览
- Oracle 动态sql
- 执行python文件报错SyntaxError: Non-ASCII character '\xe8' in file, but no encoding declared
- Android沉浸式状态栏的简单实现