iOS whose view is not in the window hierarchy

只愿长相守 提交于 2019-12-02 03:43:24

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

First:

  • Present ViewController from viewDidAppear Method or instead of ViewDidload.

Second:

I suggest to make use of completion method for present and dismiss viewcontrolelr like following example:

[self presentViewController:lOTPViewController animated:YES
                             completion:^{

        }];

UPDATE:

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:^{}];

}

Now call this method with 1 second Delaya using 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

Try to present it from rootViewController,

[self.view.window.rootViewController presentViewController:lOTPViewController animated:YES completion:nil];

Use below line of code ..

// 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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!