문제

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.)

도움이 되었습니까?

해결책

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");
}]

다른 팁

[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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top