I’m working on a view controller that can be presented modally or pushed into a navigation stack. I made it a UINavigationController subclass so that I get all the UIToolbar stuff for free. I can present it modally using:
[self presentModalViewController:myViewController animated:YES];
Problem is, UINavigationController doesn’t allow pushing another UINavigationController into it (makes sense), so this crashes it:
[self.navigationController pushViewController:myViewController animated:YES];
Would there be a way to detect how myViewController is presented and automatically have it switch between UINavigationController and UIViewController accordingly so that I don’t need 2 different classes?
In other words, myViewController would be able to detect how it’s getting presented and pushing it would come down to something like:
[self.navigationController pushViewController:myViewController.topViewController animated:YES];
NOTE: Something like this would probably do, but it’s getting too far away from the default UIViewController behaviors:
[myViewController pushIntoNavigationController:navController]; // only push myViewController.topViewController
[myViewController presentModallyInParentController:parentController]; // push the whole myViewController
In the
myViewControllersubclass, create a method something like this:Would this work or am I not understanding correctly?