Back button not made on navigation bar

2019-02-27 18:23发布

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条回答
smile是对你的礼貌
2楼-- · 2019-02-27 19:14

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;)

查看更多
登录 后发表回答