开发者

Adding UINavigationController to existing UIViewController

开发者 https://www.devze.com 2023-02-10 05:24 出处:网络
How do I add an existing UIViewController (which is presented using presentModalViewController) to a UINavigationController?

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 pushViewControlle开发者_C百科r, modally, in a UINavigationController).

Easiest way to enable this functionality?


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];


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消