我正在爲一個項目設計一個自定義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」。