在ChildViewController上添加导航栏
问题描述:
我想要一个新的视图控制器作为弹出窗口(其中有一些父视图控制器场景)。所以我决定添加childViewController(从所有面都有50px透明边框)。现在,当我添加childViewController时,我没有得到navigationBar。这是我如何添加完整大小的childViewController。在ChildViewController上添加导航栏
ShowPostTVC *postvcObj = [self.storyboard instantiateViewControllerWithIdentifier:@"ShowPostTVC"];
UINavigationController *childNavController = [[UINavigationController alloc] initWithRootViewController:postvcObj];
[self.navigationController addChildViewController:childNavController];
[self.navigationController.view addSubview:postvcObj.view];
[postvcObj didMoveToParentViewController:self];
我怎么能得到真正的导航栏上childViewController。
答
显示一个新的ViewController的正确方法是通过UINavigationController的pushViewController:animated。然后,新的ViewController有一个导航栏:
ShowPostTVC *postvcObj = [self.storyboard instantiateViewControllerWithIdentifier:@"ShowPostTVC"];
[self.navigationController pushViewController:postvcObj animated:true];
答
而不是实例化一个新UINavigationController
只需使用以下命令:
ShowPostTVC *postvcObj = [self.storyboard instantiateViewControllerWithIdentifier:@"ShowPostTVC"];
[self.navigationController pushViewController:postvcObj];
它现在的工作?任何其他问题? :) – nburk 2014-11-06 17:20:52