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

发布于 2024-09-18 21:44:10 字数 664 浏览 6 评论 0原文

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

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

在 accountViewController xib 文件中,我设置了一个导航栏。我的 MainWindow.xib 和 RootViewController.xib 也正确设置了导航栏。此外,我的应用程序委托已正确设置导航控制器(我假设):

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

[window addSubview:navigationController.view];

但是,当我加载 accountViewController 时,UINavigationBar 无处可见。是否无法在模态视图中显示 UINavigationBar?我打算用它来隐藏后退按钮,并添加一个右键......

I am loading a Modal view controller using the following code in my RootViewController:

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

In the accountViewController xib file, I have set a navigation bar. My MainWindow.xib and RootViewController.xib also have the navigation bar setup correctly. Additionally, my app delegate has setup the navigation controller (I assume) correctly:

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

[window addSubview:navigationController.view];

However, when I load my accountViewController the UINavigationBar is nowhere to be seen. Is it not possible to show a UINavigationBar in a modal view? I was planning to use it to hide the back button, and add a right button...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

护你周全 2024-09-25 21:44:10

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];
}

sha's answer is correct, but I'm giving my own answer to expand on it with a code example to make it clear.

You probably want something like:

- (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];
}
灵芸 2024-09-25 21:44:10

您需要推送的不是viewController,而是内部有viewController 的navigationController。

You need to push not viewController but navigationController that has viewController inside.

橙幽之幻 2024-09-25 21:44:10

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

You can also set the presentation style in the Attribute Inspector to "Current Context". Modal View will not cover the Navigational Bar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文