iphone - 动态更改导航 Controller 的 rootviewcontroller

标签 iphone ios xcode

我正在尝试在 didFinishLaunchingWithOptions 中为 NavigationController 更改 RootViewController
但我不知道我该怎么做。

我也浏览过这个链接:
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。然而,这不是实际的方法。

我们将不胜感激。

最佳答案

取而代之的是:

[self.window addSubview:navigationController.view];

把这个:

self.window.rootViewController = navigationController;

关于iphone - 动态更改导航 Controller 的 rootviewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10897489/

相关文章:

ios - 如何防止在 UIPicker View 中快速选择无效日期?

iphone - 来自另一个开发者帐户的 iTunes Connect 和 bundle ID

ios - 本地化不适用于 iOS 8 中的葡萄牙语(巴西)

ios - xcodebuild ios 导出存档在成功构建时失败

ios - WebStorm:设置React Native的模拟器ID

ios - 操纵约束以将 View 移动到屏幕底部

ios - UITableView 滚动时乱序

javascript - 基于网络的应用程序是否可以以某种方式访问​​智能手机的位置?并报告回来?

ios - 什么是iOS sleep 功能

ios - 是否可以直接在 XCode 8 中创建 .xcarchive?