简体   繁体   中英

How to add a < Back button to a navigation bar?

I have a simple app where I push views to the navigation. However, on one of the screens I push tab controller with two tabs. When I do this the navigation goes away when I reach the tab controller screen. On the navigation of the tab screens I would like to know how a < Back button.

Basically, I want to know how to manually create a < Back button on top left

Try this:

UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back.png"] style:UIBarButtonItemStylePlain target:self action:@selector(goBack:)];
self.navigationItem.leftBarButtonItem = backBarButton;

Then write the goBack method:

- (void)goBack:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

Note: There are some other initializer for UIBarButtonItem. Choose any one as your need.

Hope this helps.. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM