当我从 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
.viewDidAppear
Method or instead of ViewDidload
.第二:
我建议使用完成方法来呈现和关闭 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!