13
votes

I know there are lots of other questions concerning this but they don't fully explain my issue.

I go from my initial view controller SAGViewController to another SAGHomeScreenViewController via an identified storyboard custom segue, when the relevant button is pressed :

-(IBAction)goNewGame{
    [self performSegueWithIdentifier:@"startHomeSegue" sender:self];
}

It works fine but I still get the warning:

Warning: Attempt to present SAGHomeScreenViewController: 0xc43b800 on SAGViewController: 0xbaaa9f0 whose view is not in the window hierarchy!

If I comment out the performSegueWithIndentifer, the segue still works but I don't get the warning:

-(IBAction)goNewGame{
    //[self performSegueWithIdentifier:@"startHomeSegue" sender:self];
}

Why? Note that I don't have a navigation controller.
Any advice here would be appreciated, the segue still works but I don't want any warnings that I don't understand!

1
if you are not using UINavigationController then you should use modal segue. Segue works because you have wired segue in storyboard from your uibutton object to nextviewcontroller if I am not wrong.Suhit Patil
I'm using the custom segue as I want the destination view to slide in from the right. I still get the warning if I switch to a modal segueAndyOS
How do you add your current viewControllert (the controller where you call goNewGame) to the view hierarchy?Greg
I don't, it's my initial viewcontroller - in the storyboard, I have marked it as Is Initial View Controller. Should I be doing something else also? I only get the warning if I use the performSegueWithIdentifier.AndyOS
From where you are calling goNewGame method? is it getting called on unbutton tap?Suhit Patil

1 Answers

9
votes

You should remove that method and you should make connection in your storyboard from button to the second viewController.

//EXTENDED

If you want to pass something to your destination view you use prepareForSegue:sender method. This method is called every time you change the view via segue:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"YOURSEGUEIDENTIFIER"])
    {
        YourViewController *yourVC = [segue destinationViewController];
    }
}

//EXTENDED

This is happening because you have connected your segue in two ways one is in code and another is in storyboard. You have to remove one of those. You can remove your IBAction from your code (so you will have just connection in storyboard) or you can remove your connection in storyboard (from your button to destination view controller) and add it again but this time drag it from your source view controller (not button) to your destination view controller. Don't forget set up segue identifier. If you use storyboard I would recommend you to remove your IBAction from code, less code to manage. Hope this help.