问题描述
我正在RootViewController中使用以下代码加载模态视图控制器:
I am loading a Modal view controller using the following code in my RootViewController:
[self.navigationController presentModalViewController:accountViewController animated:YES];
在accountViewController xib文件中,我设置了一个导航栏.我的MainWindow.xib和RootViewController.xib也正确设置了导航栏.此外,我的应用程序代表已正确设置了导航控制器(我认为):
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];
但是,当我加载accountViewController时,看不到UINavigationBar.不能在模式视图中显示UINavigationBar吗?我打算用它隐藏后退按钮,并添加一个右键...
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...
推荐答案
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:
- (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];
}
这篇关于UINavigationBar拒绝在模态视图控制器中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!