Objective c 我在名为iAction的视图中没有导航栏?
我的主菜单(ViewController)嵌入在我在Xcode4中的故事板中添加的NavigationController中。 我的菜单中有一个按钮,显示一个新视图。要显示它,我使用:Objective c 我在名为iAction的视图中没有导航栏?,objective-c,ios,uinavigationcontroller,ibaction,Objective C,Ios,Uinavigationcontroller,Ibaction,我的主菜单(ViewController)嵌入在我在Xcode4中的故事板中添加的NavigationController中。 我的菜单中有一个按钮,显示一个新视图。要显示它,我使用: - (IBAction) display : (id) sender { if(!anotherView) anotherView = [[AnotherView alloc] initWithNibName:@"AnotherView" bundle:nil]; [self presentMod
- (IBAction) display : (id) sender
{
if(!anotherView) anotherView = [[AnotherView alloc] initWithNibName:@"AnotherView" bundle:nil];
[self presentModalViewController:anotherView animated:NO];
}
“我的另一个视图”及其所有对象和元素都正确显示。不包括我的NavigationController栏,它不会出现。为什么?
感谢您的建议您正在以模式演示viewController。如果要使用导航控制器,必须将视图推送到导航堆栈上 替换
[self presentModalViewController:anotherView animated:NO];
与
您正在以模式呈现视图
[self.navigationController pushViewController:anotherView animated:YES]
当然,您真正想要做的不是像这样不必要地混合和匹配故事板和非故事板流,而是让故事板为您这样做您仍然可以在不丢失导航栏的情况下以模式显示视图。请尝试以下代码:
AnotherView *tempAnotherView = [[AnotherView alloc] initWithNibName:@"AnotherView" bundle:nil];
[self setAnotherView:tempAnotherView];
[tempAnotherView release];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:self.anotherView] autorelease];
[self.navigationController presentModalViewController:navController animated:YES];
希望有帮助!:)
AnotherView *tempAnotherView = [[AnotherView alloc] initWithNibName:@"AnotherView" bundle:nil];
[self setAnotherView:tempAnotherView];
[tempAnotherView release];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:self.anotherView] autorelease];
[self.navigationController presentModalViewController:navController animated:YES];