当我从PassCode Controller移动到OTP ViewController时,iam在控制台中收到以下错误:
警告:尝试出示< OTPController:0x1e56e0a0> on< PassCodeController:0x1ec3e000>其视图不在窗口层次结构中!
这是我用来更改观看次数的代码:
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];
答案 0 :(得分:3)
发生这种情况是因为两个viewcontroller同时存在和解除,或者你试图在viewcontroller open ViewDidload
方法中立即呈现ViewController所以
<强>首先强>
viewDidAppear
方法或代替ViewDidload
。<强>第二强>
我建议使用目前的完成方法并解除viewcontrolelr,如下例所示:
[self presentViewController:lOTPViewController animated:YES
completion:^{
}];
<强>更新强>
创建一个单独的方法来呈现OTPViewController,如下所示:
-(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代码[self dismissViewControllerAnimated:YES completion:^{
[self performSelector:@selector(PresentOTPViewController) withObject:self afterDelay:1.0 ];
}]; // this is the dismiss method of PassCodeViewController
吨
答案 1 :(得分:2)
尝试从rootViewController中显示它,
[self.view.window.rootViewController presentViewController:lOTPViewController animated:YES
completion:nil];
答案 2 :(得分:1)
使用以下代码行..
// you need to create UIStoryboard object by giving name of your storyboard
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// here you need to create storyboard ID of perticular view where you need to navigate your app
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"viewContIdentifire"];
// if use presentViewController this will not enables you to go back to previous view
[self presentViewController:vc animated:NO completion:nil];
**// OR**
// using pushViewController lets you to go back to the previous view
[self.navigationController pushViewController:vc animated:YES];