Why is my view manager not in the window hierarchy?

Using storyboards, MainMenuViewController presents Number1ViewController modally with this:

-(void) goToNumbers {

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

}

      

Then Number1ViewController presents Number2ViewController like this:

-(void)nextLevel {

     [self performSegueWithIdentifier: @"segueToLevel2" sender: self];
}

      

xCode then issues this warning:

2013-01-23 12:09:49.873 ToddlerTeacherMini[7574:907] Warning: Attempt to present <Number2ViewController: 0x1fddc720> on <Number1ViewController: 0x1fdc7380> whose view is not in the window hierarchy!

      

Evertything I see on the internet about this warning says that you cannot represent the VC in another VC's viewDidLoad method and move your code to the viewWillAppear method, that will fix it. I don't call this segue from viewDidLoad, but rather call him later, so I'm not sure why this is happening.

I suggest VC similarly elsewhere in my application with no problem and can't figure out what's different here, any help?

To be clear, everything works as expected in my application. I just don't want to ignore this message and return it and bite me later.


Regarding Todd Kerpelman, I looked at where my nextLevel method called me. Breakpoint didn't tell me much, but dug a little more into NSLog. I came up with this:

-(void)nextLevel {


    if (nextLevelHasNotBeenCalled == 0){

       [self performSegueWithIdentifier: @"segueToLevel2" sender: self];
        NSLog(@"Segue was called here.");

    }

    nextLevelHasNotBeenCalled ++;
    NSLog(@"Next level has been called %i times!", nextLevelHasNotBeenCalled);


}

      

Log:

2013-01-26 02:04:12.579 ToddlerTeacherMini[9203:907] Segue was called here.
2013-01-26 02:04:12.593 ToddlerTeacherMini[9203:907] Next level has been called 1 times!
2013-01-26 02:04:14.789 ToddlerTeacherMini[9203:907] Next level has been called 2 times!

      

It's pretty clear that nextLevel is getting called twice and that is causing my problem.

+3


source to share


1 answer


This sounds like a case of your code accidentally calling nextLevel

when you don't expect it. (Probably as a side effect of some unrelated method being called in your Number1ViewController method viewDidLoad

.)



Have you tried adding a breakpoint to your method nextLevel

and seeing how / where it is called? This is probably the best way to at least confirm (or eliminate) this possibility.

+2


source







All Articles