UINavigationBar 拒绝在模态视图控制器中显示
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
sha的答案是正确的,但我给出了我自己的答案,并用代码示例对其进行了扩展,以使其清楚。
你可能想要这样的东西:
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:
您需要推送的不是viewController,而是内部有viewController 的navigationController。
You need to push not viewController but navigationController that has viewController inside.
您还可以在属性检查器中将呈现样式设置为“当前上下文”。模态视图不会覆盖导航栏。
You can also set the presentation style in the Attribute Inspector to "Current Context". Modal View will not cover the Navigational Bar.