在呈现模态视图控制器后,将BarButtons添加到UINavigationBar [英] Adding BarButtons to a UINavigationBar after presenting a modal view controller
问题描述
我正在使用实用程序应用程序的模板。在FlipSideViewController中,我为UINavigationController,navController添加了一个IBOutlet。在代码中,我添加了navController就好了。 rootViewController完美加载:
I'm using the template for a utility Application. In the FlipSideViewController, I added an IBOutlet for a UINavigationController, navController. In the code, I added the navController just fine. The rootViewController loads perfectly:
navController.viewControllers = [[NSArray arrayWithObject:rootViewController] retain];
[self.view addSubview:navController.view];
我改变了navController的颜色就好了:
I changed the color of the navController just fine:
navController.navigationBar.tintColor = [UIColor colorWithRed:0.6 green:0.75 blue:0.6 alpha:1.0];
navController.navigationBar.translucent = NO;
我做了一个按钮(注意:完成指的是一个解除modalviewcontroller的IBAction): / p>
I make a button (note: "done" refers to a IBAction that dismisses the modalviewcontroller):
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"TEST" style:UIBarButtonItemStyleDone target:self action:@selector(done:)];
我使用该按钮创建一个navItem:
I make a navItem using that button:
UINavigationItem *backNavItem = [[UINavigationItem alloc] initWithTitle:@"TESTTEST"];
[backNavItem setRightBarButtonItem:backButton animated:YES];
我尝试添加该按钮:
[navController.navigationBar pushNavigationItem:backNavItem animated:YES];
上面的代码惨遭失败。我显然无法向navController添加按钮,因为:
This above code fails miserably. I apparently can't add buttons to the navController because:
***因未捕获的异常而终止应用
'NSInternalInconsistencyException' ,
理由:'无法调用
pushNavigationItem:animated:直接
在由
控制器管理的UINavigationBar上。'
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot call pushNavigationItem:animated: directly on a UINavigationBar managed by a controller.'
我是否必须制作一个单独的UINavigationBar,它以某种方式连接到我的navController?我试过去那条路但没有用。
Do I have to make a separate UINavigationBar that's somehow connected to my navController? I tried going that route but with no avail.
推荐答案
我检查了NavBar这里:
I checked out "NavBar" here:
非常了解如何添加按钮。您必须从正在显示的正确ViewController中添加按钮。
Excellent insight on how to do add buttons. You have to add buttons from the correct ViewController being displayed.
这篇关于在呈现模态视图控制器后,将BarButtons添加到UINavigationBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!