当我从 PassCode 控制器移动到 OTP ViewController 时,我在控制台中收到以下错误:
警告:尝试在
PassCodeController: 0x1ec3e000> 其视图不在窗口层次结构中!
这是我用来在视图之间更改的代码:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
OTPViewController *lOTPViewController = [storyboard instantiateViewControllerWithIdentifier:@"OTPViewController"];
lOTPViewController.comingFromReg = true;
[self presentViewController:lOTPViewController animated:YES
completion:nil];
我正在展示来自注册视图控制器的密码控制器:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PassCodeViewController *passVC = [storyboard instantiateViewControllerWithIdentifier:@"PassCodeViewController"];
[self presentViewController:passVC animated:YES completion:nil];
发生这种情况是因为两个视图控制器同时存在并关闭,或者您试图在视图控制器打开时立即呈现 ViewControllerViewDidload
方法如此
First:
- 当前 ViewController 来自
viewDidAppear
方法或代替ViewDidload
.
Second:
我建议使用完成方法来呈现并关闭 viewcontrolelr,如下例所示:
[self presentViewController:lOTPViewController animated:YES
completion:^{
}];
UPDATE:
创建一个单独的方法来呈现 OTPViewController,如下所示:
-(void)PresentOTPViewController
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
OTPViewController *lOTPViewController = [storyboard instantiateViewControllerWithIdentifier:@"OTPViewController"];
lOTPViewController.comingFromReg = true;
[self presentViewController:lOTPViewController animated:YES
completion:^{}];
}
现在使用 1 秒延迟调用此方法performSelector
[self performSelector:@selector(PresentOTPViewController) withObject:self afterDelay:1.0 ];
您需要将上面的执行选择代码放入
[self dismissViewControllerAnimated:YES completion:^{
[self performSelector:@selector(PresentOTPViewController) withObject:self afterDelay:1.0 ];
}]; // this is the dismiss method of PassCodeViewController
t
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)