本文介绍了动态更改用于导航控制器的rootviewcontroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 didFinishLaunchingWithOptions 中的 NavigationController 中更改 RootViewController .
但是我不知道该怎么办.

I'm trying to change RootViewController for NavigationController in didFinishLaunchingWithOptions.
But I don't know how can I do that.

我也通过此链接:
http://starterstep.wordpress.com/2009/03/05/changing-a-uinavigationcontroller%E2%80%99s-root-view-controller/

这是我在 didFinishLaunchingWithOptions 中的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    UIViewController *rootController=[[HomePageController alloc] initWithNibName:@"HomePageController" bundle:nil];
    navigationController=[[UINavigationController alloc] initWithRootViewController:rootController];

//    presentation=[[PresentationController alloc]initWithNibName:@"PresentationController" bundle:nil];
//    
//    navigationController=[[UINavigationController alloc]initWithRootViewController:presentation];
//    
//    presentationList=[[PresentationListController alloc]initWithNibName:@"PresentationListController" bundle:nil];
//    
//    UINavigationController *listnavigation = [[UINavigationController alloc] initWithRootViewController:presentationList];
//    
//    revealer=[[ZUUIRevealController alloc]initWithFrontViewController:navigationController rearViewController:listnavigation];

    [self.window addSubview:navigationController.view];

    [self.window makeKeyAndVisible];
    return YES;
}

现在我发表评论,然后运行应用程序以更改 rootviewcontroller .但这不是实际的方法.

Right now I comment and then run application to change rootviewcontroller. However this is not the practical approach.

任何帮助将不胜感激.

推荐答案

代替此:

[self.window addSubview:navigationController.view];

输入:

self.window.rootViewController = navigationController;

这篇关于动态更改用于导航控制器的rootviewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 14:33