9
votes

How do I add an existing UIViewController (which is presented using presentModalViewController) to a UINavigationController?

When user tap on button, a new copy of my detail view need to be pushed. (In other words, pushViewController displaying pushViewController, modally, in a UINavigationController).

Easiest way to enable this functionality?

2
It's not clear what you're asking. Do you want to present a UINavigationController modally? That "feels" wrong but I don't know for sure.Bogatyr
that's the simplified description... presenting UINavigationController modally... (but modifying existing UIViewController)marko

2 Answers

37
votes

how do you create your modal viewcontroller? Just wrap the controller into a UINavigationController

Let's assume your modal code is like this:

MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease];
[self presentModalViewController:vc animated:YES];

Then change it into something like this:

MyExampleViewController *vc = [[[MyExampleViewController alloc] initWithNibName:@"MyExample" bundle:nil] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
[self presentModalViewController:navController animated:YES];
0
votes

I think you need to add a navigation controller in your delegate, after that you can push the view. So that you can push the view from anywhere in your application.

on AppDelegate.h

UINavigationController *navig;

on AppDelegate.M

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    navig = [[UINavigationController alloc] initwithRootViewController:viewController.view];

    //[navig pushViewController:viewController animated:YES];
    [self.window addSubview:navig.view];
    [self.window makeKeyAndVisible];

    return YES;
}