iOS视图不在窗口层次结构中的iOS [英] iOS whose view is not in the window hierarchy

查看:88
本文介绍了iOS视图不在窗口层次结构中的iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从PassCode控制器移动到OTP ViewController时,iam在控制台中收到以下错误:


警告:尝试出示< OTPController:0x1e56e0a0> on<
PassCodeController:0x1ec3e000>其视图不在窗口层次结构中!

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呈现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 of ViewDidload.

第二名:

我建议使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆