Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Tex-Twil

macrumors 68030
Original poster
May 28, 2008
2,501
15
Berlin
Hi,
I have a framework project which offers a view controller (MyViewController) ready to use for a specific task and I want it to be all the time embedded in a navigation controller. It's analog to e.g. MFMailComposeViewController. Apple says that UINavigationController should not be subclassed so my question is how to implement this situation.

The user of the framework uses MyViewController in this way:


Code:
MyViewController *myViewController = [[MyViewController alloc] init];
myViewController.mydelegate = self;
[self presentModalViewController: myViewController animated:YES];

When the MyViewController is presented, I want it to be already embedded in a navigation controller. I do not want the user to do it.

How can I do it?

cheers,
Tex
 
Last edited:
Navigation Controllers

You would probably want to place the instance of MyViewController inside of a navigation controller in its init method. Check out apples documentation on how to create navigation controllers and load them with views.
 
You would probably want to place the instance of MyViewController inside of a navigation controller in its init method. Check out apples documentation on how to create navigation controllers and load them with views.

This is what the user of the framework can do:

Code:
MyViewController *myViewController = [[MyViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myViewController];

but what I want is to ensure that MyViewController will be always in a navigation controller.
 
You can write a class method in your view controller class that creates the nav controller, the new view controller, presents them, and returns the pointer to the new view controller.

Or you can add a show or present method to your class and it will show the view controller in the nav controller.

Or you can add a class method to your class that takes a navigation controller and adds an object of your class to the navigation controller.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.