问题描述
当我从PassCode控制器移动到OTP ViewController时,iam在控制台中收到以下错误:
这是我的代码用于在视图之间切换:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
OTPViewController *lOTPViewController = [storyboard instantiateViewControllerWithIdentifier:@"OTPViewController"];
lOTPViewController.comingFromReg = true;
[self presentViewController:lOTPViewController animated:YES
completion:nil];
我从RegistrationViewController呈现PassCode控制器:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PassCodeViewController *passVC = [storyboard instantiateViewControllerWithIdentifier:@"PassCodeViewController"];
[self presentViewController:passVC animated:YES completion:nil];
推荐答案
这是因为两个viewcontroller存在和解除同时或者你试图在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
.
第二名:
我建议使用present的完成方法并解除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:^{}];
}
现在使用<$ c使用1秒Delaya调用此方法$ c> performSelector
[self performSelector:@selector(PresentOTPViewController) withObject:self afterDelay:1.0 ];
您需要在上面执行选择代码
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!