6

我是 iPhone 新手,

我想将我的课程更改Rootviewcontroller为我的新课程并使其成为导航控制器。

这是我的代码片段,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    


    UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:detailViewController];
    [self.window addSubview:navigationController.view];

    [self.window makeKeyAndVisible];


    return YES;
}

SIGABRT'adding a root view controller <NewClass: 0x6a8dd50> as a child of view controller:

4

4 回答 4

13

每当你想设置:

DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:detailViewController];
self.window.rootViewController =nil;
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];

编辑:直接用于AppDelegate instance设置rootViewControllerUIWindow如上所示。

于 2012-09-03T07:18:05.703 回答
2

代替:

[self.window addSubview:navigationController.view];

制作:navigationController_ rootViewController_window

 self.window.rootViewController = navigationController;

另外,是detailViewController类型UINavigationController吗?您不能将其设置UINavigationController为另一个UINavigationController对象的根。

于 2012-09-03T07:15:45.707 回答
1

只需添加这一行,

RootViewController *defaultViewController=[[RootViewController alloc]initWithNibName:@"NAME_OF_XIB" bundle:nil];

在 UINavigationController 的初始化之前,

RootViewController *defaultViewController=[[RootViewController alloc]initWithNibName:@"NAME_OF_XIB" bundle:nil];
UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:detailViewController];
[self.window addSubview:navigationController.view];

[self.window makeKeyAndVisible];
return YES;
于 2012-09-03T07:57:50.083 回答
0

将您的 RootViewController 更改为 NavigationController..

UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:self.detailViewController];
于 2013-05-03T11:53:38.083 回答