导航栏上没有后退按钮 [英] Back button not made on navigation bar
问题描述
我从一个基于导航的项目开始,然后将更多视图推送到控制器上.问题是,如果我没有给导航项目添加标题,则不会绘制后退按钮!仅当我给导航栏指定标题时,后退按钮才会出现.看来如果 NO 标题,苹果不能写"back"或"go back".我不想给导航项目添加标题(我将在视图内部使用标签).那我该如何解决呢?
I started out with a navigation based project and am pushing further views onto the controller. The problem is that if I do not give a title to the navigation item then the back button is not drawn! Only if I give the navigation bar a title, will the back button come. It seems apple could'nt write "back" or "go back" in case of NO title. I do not want to give the navigation item a title(I'll use a label inside my view). So how do I fix this?
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"Home"; /// <- without setting the title, the back button won't show !
}
在didLoad视图中,如果我删除标题,则后退按钮将不会显示
In the view didLoad method, if I remove the title, the back button won't show
推荐答案
只需自己创建后退按钮即可:
Just create the back button yourself:
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
[[self navigationItem] setBackBarButtonItem:back];
[back release];
}
(如果您更喜欢点符号,请按self.navigationItem.backBarButtonItem = back;
)
(If you prefer dot notation, self.navigationItem.backBarButtonItem = back;
)
这篇关于导航栏上没有后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!