我正在为一个项目设计一个自定义UIViewContainerController
。我在此容器中保存了一个contentView
以管理我的Childviewcontroller's
视图。当我单独添加childviewcontroller
时,它工作正常。但是一些childviewcontrollers
必须使用“导航控制器”&进行初始化,这是我遇到实现问题的地方。将带有NavigationController的ChildViewController添加到ContainerController
我用平时initWithRootViewController
方法上“navigationcontroller”给init(初始化)我的“childvc” &那我怎么与导航栏一起加入这个我contentView
?
这是我使用的代码“childvc”没有“导航控制器”&它工作正常。
// in my containerview controller's add childview method.
ChildViewController1 *vc = [ChildViewController1 new];
[self addChildViewController:vc]; // self = container vc
vc.view.frame = self.contentView.bounds;
[self.contentView addSubview:vc.view]; // contentView is the space i've kept to add childvcs
[vc didMoveToParentViewController:self];
现在,当我尝试使用“childvc”与“navigationcontroller”初始化(因为有这个“childvc”甲流),我得到的错误&什么,我需要知道的是我怎么将它添加到我的contentView
以及导航栏。 (就像在tabbarcontroller中)。
这是我使用初始化“childvc”与“导航控制器”的代码:
ChildViewController1 *vc = [ChildViewController1 new];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
我做了简单的工程“Here”公共仓库。
我已阅读标签栏/导航控制器的文档&在苹果文档中创建自定义容器视图控制器,但似乎缺少重要的东西。 链接是“Here”。