我正在开发一个应用程序,我必须在其中并排显示多个 View Controller ( Split View)。为此,我添加了 View 作为 subview Controller 。
目标:我想在一个 subview Controller 上显示导航栏,同时在父 View Controller 上显示单独的导航栏。
问题: 导航栏未显示在 subview Controller 上。
编辑:我还将父 View Controller 的导航栏设置为隐藏,但是当调用 subview Controller 时,导航栏出现在父 View Controller 上,而不是 subview Controller 上。
添加 subview Controller 的代码是:
MyChildViewController *childViewController = [[MyChildViewController alloc] initWithNibName:@"MyChildViewController" bundle:nil];
[self addChildViewController:childViewController];
[childViewController.view setFrame:CGRectMake(0.0f, 0.0f, self.rightContainerView.frame.size.width, self.rightContainerView.frame.size.height)];
[self.rightContainerView addSubview:childViewController.view];
[childViewController didMoveToParentViewController:self];
此代码运行良好, subview Controller 可以完美添加。我想知道是否可能?
提前致谢。
最佳答案
我通过以下方式自行解决了这个问题:
MyChildViewController *childViewController = [[MyChildViewController alloc] initWithNibName:@"MyChildViewController" bundle:nil];
[childViewController.view setFrame:CGRectMake(0.0f, 0.0f, self.rightContainerView.frame.size.width, self.rightContainerView.frame.size.height)];
UINavigationController *childNavController = [[UINavigationController alloc] initWithRootViewController:childViewController];
childNavController.view.frame = childViewController.view.frame;
[self addChildViewController:childNavController];
[self.rightContainerView addSubview:childNavController.view];
[childNavController didMoveToParentViewController:self];
现在,当我在 MyChildViewController
中添加导航栏时,它会添加到 subview Controller 中,并且不会影响父 View Controller 的导航栏。 subview Controller 的 navigationController
属性也不同于父 View Controller 的 navigationController
属性,两者都有自己的导航堆栈。
关于ios - 在 subview Controller 中显示导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22935229/