我想在viewcontroller中添加2个navigationControllers。这两个navigationController是完全独立的,没有链接。我想在另一个旁边显示这两个navigationViewController,比如splitviewcontroller。
使用childViewController,我成功地为2个viewControllers添加了我想要的位置和大小。但是当我尝试使用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];
答案 0 :(得分:-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];