When I make a screen transition in viewDidAppear, it says which view is not in the window hierarchy!

Asked 2 years ago, Updated 2 years ago, 79 views

I wrote the following code, but when I run it, it says which view is not in the window hierarchy!

LoginViewController.m

-(void)viewDidAppear:(BOOL)animated{
  [super viewDidAppear: animated ];

  [self presentViewController:
            [self.storyboard]
                instantiateViewControllerWithIdentifier:@"AgreementVC"]
                     animated —YES
                   completion:nil];
}

@ "AgreementVC" is the storyboard ID assigned to the AgreementViewController.
The LoginViewController appears first.

objective-c

2022-09-30 17:06

1 Answers

I tried it on hand, but I was able to transition without any problems.
Tried
·Add a UIViewController to the Main.storyboard
·Added CustomViewController class
·Associate CustomViewController with UIViewController added to Main.storyboard
 class —CustomViewController
 Storyboard ID:CustomVC
·Add the following code to ViewController (made when creating the project)

 - (void) viewDidAppear: (BOOL) animated
{
  [super viewDidAppear: animated ];
  [self presentViewController:
            [self.storyboard]
                instantiateViewControllerWithIdentifier:@"CustomVC"]
                     animated —YES
                   completion:nil];
}

Also, I tried the pattern using Segue, and it worked fine.

[self performSegueWithIdentifier:@"toCustomVC" sender:self];

The error (which view is not in the window hierarchy!) occurs when you use viewDidLoad to perform screen transitions, so if you are doing something with viewDidLoad, why don't you comment out and try it?


2022-09-30 17:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.