-1

我想在视图控制器中添加 2 个导航控制器。这 2 个 navigationController 是完全独立的,没有链接。我想将这 2 个 navigationViewController 并排显示,例如 splitviewcontroller。

使用 childViewController,我成功地将 2 个 viewController 添加到我想要的位置和大小。但是当我尝试使用 navigationController 时,它们会占据所有屏幕并显示在点 (0,0)。我尝试更改 navigationController 的框架,但没有任何改变。

任何人都可以帮助我吗?

非常感谢。

编辑:这是我用来添加 childVC 的代码:

self.meetingsListViewController = [[MeetingsListViewController alloc] initWithNibName:@"MeetingsListViewController" bundle:nil];
self.navCalendar = [[UINavigationController alloc] initWithRootViewController:meetingsListViewController];
[self.navCalendar setNavigationBarHidden:NO];

self.meetingsListViewController.view.frame = CGRectMake(10, 54, self.view.frame.size.width/2-20, self.view.frame.size.height - 64);
self.navCalendar.view.frame = self.meetingsListViewController.view.frame;    
self.navCalendar.view.autoresizesSubviews = NO;

[self addChildViewController:meetingsListViewController];
[self.view addSubview:self.meetingsListViewController.view];
[self.navCalendar didMoveToParentViewController:self];


self.listPlaylistViewController = [[ListPlaylistViewController alloc] initWithNibName:@"ListPlaylistViewController" bundle:nil];
self.navPlaylist = [[UINavigationController alloc] initWithRootViewController:listPlaylistViewController];
[self.navPlaylist setNavigationBarHidden:NO];

self.listPlaylistViewController.view.frame = CGRectMake(self.view.frame.size.width/2+10, 54, self.view.frame.size.width/2-20, self.view.frame.size.height - 64);
self.navPlaylist.view.frame = self.listPlaylistViewController.view.frame;
self.navPlaylist.view.autoresizesSubviews = NO;

[self addChildViewController:listPlaylistViewController];
[self.view addSubview:self.listPlaylistViewController.view];
[self.navPlaylist didMoveToParentViewController:self];
4

1 回答 1

-1

简单的方法是将两个容器视图添加到情节提要中的控制器视图中,这将为您提供两个嵌入式控制器。我认为您应该能够选择这些嵌入式控制器并使用菜单将它们嵌入导航控制器中。如果这不起作用,只需删除那些嵌入式控制器,拖出导航控制器,从容器视图添加控件拖动以嵌入它们。

编辑后:

如果您想在代码中执行此操作,那么您发布的内容有几处错误。addChildViewController、addSubview 和 didMoveToParentViewController 调用都应该针对导航控制器,而不是内容控制器。也不需要设置内容控制器的框架,直接设置导航控制器的框架:

self.meetingsListViewController = [[UIViewController alloc] initWithNibName:@"MeetingsListViewController" bundle:nil];
    self.navCalendar = [[UINavigationController alloc] initWithRootViewController:self.meetingsListViewController];

    self.navCalendar.view.frame = CGRectMake(10, 54, self.view.frame.size.width/2-20, self.view.frame.size.height - 64);

    [self addChildViewController:self.navCalendar];
    [self.view addSubview:self.navCalendar.view];
    [self.navCalendar didMoveToParentViewController:self];


    self.listPlaylistViewController = [[UIViewController alloc] initWithNibName:@"ListPlaylistViewController" bundle:nil];
    self.navPlaylist = [[UINavigationController alloc] initWithRootViewController:self.listPlaylistViewController];

    self.navPlaylist.view.frame = CGRectMake(self.view.frame.size.width/2+10, 54, self.view.frame.size.width/2-20, self.view.frame.size.height - 64);

    [self addChildViewController:self.navPlaylist];
    [self.view addSubview:self.navPlaylist.view];
    [self.navPlaylist didMoveToParentViewController:self];
于 2013-04-05T14:33:39.160 回答