【问题标题】:Add Navigation Bar on ChildViewController在 ChildViewController 上添加导航栏
【发布时间】:2015-01-03 02:28:28
【问题描述】:

我想要一个新的视图控制器作为弹出窗口(其中有一些父视图控制器场景)。所以我决定添加 childViewController (从四面八方都有 50px 透明边框。)现在当我添加 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 上获得真正的导航栏。

【问题讨论】:

  • 现在可以用了吗?还有其他问题吗? :)

标签: ios iphone ios7 uinavigationbar childviewcontroller


【解决方案1】:

显示新 ViewController 的正确方法是通过 UINavigationController 的 pushViewController:animated。然后新的 ViewController 有一个 NavigationBar:

ShowPostTVC *postvcObj = [self.storyboard instantiateViewControllerWithIdentifier:@"ShowPostTVC"];
[self.navigationController pushViewController:postvcObj animated:true]; 

【讨论】:

    【解决方案2】:

    不用实例化一个新的UINavigationController,只需使用以下代码:

    ShowPostTVC *postvcObj = [self.storyboard instantiateViewControllerWithIdentifier:@"ShowPostTVC"];
    [self.navigationController pushViewController:postvcObj];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多