iOS whose view is not in the window hierarchy(视图不在窗口层次结构中的 iOS)
问题描述
当我从 PassCode 控制器移动到 OTP ViewController 时,我在控制台中收到以下错误:
警告:尝试呈现 <OTPController: 0x1e56e0a0 > on
Warning: Attempt to present < OTPController: 0x1e56e0a0 > on < PassCodeController: 0x1ec3e000> whose view is not in the window hierarchy!
这是我用来在视图之间切换的代码:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
OTPViewController *lOTPViewController = [storyboard instantiateViewControllerWithIdentifier:@"OTPViewController"];
lOTPViewController.comingFromReg = true;
[self presentViewController:lOTPViewController animated:YES
completion:nil];
我正在从 RegistrationViewController 展示密码控制器:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PassCodeViewController *passVC = [storyboard instantiateViewControllerWithIdentifier:@"PassCodeViewController"];
[self presentViewController:passVC animated:YES completion:nil];
推荐答案
这是因为两个viewcontroller同时存在和dismiss,或者你试图在viewcontroller打开时立即展示ViewController ViewDidload
方法如此
That happen because of two viewcontroller present and dismiss at a same time or you are trying to present ViewController immediately at the viewcontroller open ViewDidload
method so
第一:
- 从
viewDidAppear
方法中呈现 ViewController 或代替ViewDidload
.
- Present ViewController from
viewDidAppear
Method or instead ofViewDidload
.
第二:
我建议使用完成方法来呈现和关闭 viewcontrolelr,如下例所示:
I suggest to make use of completion method for present and dismiss viewcontrolelr like following example:
[self presentViewController:lOTPViewController animated:YES
completion:^{
}];
更新:
创建一个显示 OTPViewController 的单独方法,如下所示:
Create a separate method of presenting a OTPViewController like following:
-(void)PresentOTPViewController
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
OTPViewController *lOTPViewController = [storyboard instantiateViewControllerWithIdentifier:@"OTPViewController"];
lOTPViewController.comingFromReg = true;
[self presentViewController:lOTPViewController animated:YES
completion:^{}];
}
现在使用 performSelector
[self performSelector:@selector(PresentOTPViewController) withObject:self afterDelay:1.0 ];
你需要把上面的performselect代码放在
You need to put above performselect code in
[self dismissViewControllerAnimated:YES completion:^{
[self performSelector:@selector(PresentOTPViewController) withObject:self afterDelay:1.0 ];
}]; // this is the dismiss method of PassCodeViewController
t
这篇关于视图不在窗口层次结构中的 iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:视图不在窗口层次结构中的 iOS


- UITextView 内容插图 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- URL编码Swift iOS 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01