Pergunta

In MyMainViewController, I present a navigation controller like this:

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UINavigationController* nc = [storyboard instantiateViewControllerWithIdentifier:@"NAVIGATION_CONTROLLER_ID"];
[self presentViewController:nc animated:YES completion:nil];

Later, from somewhere within the view hierarchy of the UINavigationController, I need to return to MyMainViewController. How can I do this?

(Note: MyMainViewController is defined in a .XIB, and not in the storyboard where the UINavigationController and it's children are defined.)

Foi útil?

Solução

It sounds like you have modally presented a NavController that you want to remove. Modally presented VC's can remove themselves.

Somewhere in your NavController add:

[self dismissViewControllerAnimated:YES completion:^{
    NSLog(@"Dismissed nav controller modally");
}]

Outras dicas

[self.navigationController popToViewController:[[self.navigationController viewControllers] objectAtIndex:2] animated:YES];

I gues you know the index of your view controller. If you simply want to return to the rootViewController you can do it like

[self.navigationController popToRootViewControllerAnimated:YES];

If you want to push new viewController to the navigation stack just do it like

MyMainViewController *mainController = [[MyMainViewController alloc] initWithNibName:@"MyMainViewController" bundle:nil];
[self.navigationController pushViewController:desController animated:YES];

Returning to the previous viewController would be

[self dismissViewControllerAnimated:YES completion:nil];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top