Back button not made on navigation bar

﹥>﹥吖頭↗ 提交于 2019-12-02 12:39:58

问题


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 !
}

In the view didLoad method, if I remove the title, the back button won't show


回答1:


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];
}

(If you prefer dot notation, self.navigationItem.backBarButtonItem = back;)



来源:https://stackoverflow.com/questions/6921639/back-button-not-made-on-navigation-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!