将返回按钮添加到导航栏 [英] Adding back button to navigation bar
问题描述
我添加了一个导航栏到UIViewController。它仅从另一个UIViewController显示。我想有一个左侧背按钮形状类似于一个箭头,就像正常的导航栏后退按钮。看来我只能通过IB添加一个条形图按钮。我猜想后退按钮需要以编程方式添加。关于我应该如何做这个的任何建议?
I've added a navigation bar to a UIViewController. It is displayed from another UIViewController only. I'd like to have a left side back button that is shaped similar to an arrow, just like the normal navigation bar back button. It seems I can only add a bar button through IB. I'm guessing the back button needs to be added programmatically. Any suggestions on how I should do this?
目前,在RootController,我推一个UIViewController(viewB)只需做一个addSubView。在viewB中,我要显示导航栏。
Currently, in the RootController, I push another UIViewController (viewB) by simply doing an addSubView. In viewB, I want to display the navigation bar. The app is view based, not navigation controller based.
推荐答案
如果您使用的是导航控制器:
If you're using a navigation controller:
MyViewController *_myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
[[self navigationController] pushViewController:_myViewController animated:YES];
UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:nil action:nil];
self.navigationItem.backBarButtonItem = _backButton;
[_backButton release], _backButton = nil;
[_myViewController release], _myViewController = nil;
如果您不使用导航控制器,请查看 Three20 style 组件来制作自定义栏按钮。
If you're not using a navigation controller, look into the Three20 style components to make custom bar buttons.
这篇关于将返回按钮添加到导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!