代码之家  ›  专栏  ›  技术社区  ›  mootymoots

UINavigationBar拒绝在模态视图控制器中显示

  •  3
  • mootymoots  · 技术社区  · 14 年前

    我正在RootViewController中使用以下代码加载模态视图控制器:

    [self.navigationController presentModalViewController:accountViewController animated:YES];
    

    在accountViewController xib文件中,我设置了一个导航栏。我的主窗口.xib以及根视图控制器.xib还要正确设置导航栏。此外,我的应用程序代理已正确设置导航控制器(我假设):

    UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
    self.navigationController = aNavigationController;
    
    [window addSubview:navigationController.view];
    

    但是,当我加载accountViewController时,UINavigationBar就不见了。无法在模式视图中显示UINavigationBar吗?我打算用它来隐藏后退按钮,并添加一个右按钮。。。

    3 回复  |  直到 14 年前
        1
  •  6
  •   Shaggy Frog    14 年前

    sha的答案是正确的,但是我给出了我自己的答案,并用一个代码示例对其进行了扩展。

    - (void)showAccountViewController
    {
        AccountViewController* accountViewController = [[AccountViewController alloc] initWithNibName:@"AccountView" bundle:nil];
        ...
        // Initialize properties of accountViewController
        ...
        UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:accountViewController];
        [self.navigationController presentModalViewController:navController animated:YES];
        [navController release];
        [accountViewController release];
    }
    
        2
  •  1
  •   sha    14 年前

        3
  •  0
  •   Sabya    10 年前

    也可以在属性检查器中将表示样式设置为“当前上下文”。模态视图不会覆盖导航栏。

    推荐文章