简体   繁体   English

如何在导航栏中添加<返回按钮?

[英]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. 在标签屏幕的导航中,我想知道< Back按钮的方式。

Basically, I want to know how to manually create a < Back button on top left 基本上,我想知道如何手动创建左上方的< Back按钮

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: 然后编写goBack方法:

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

Note: There are some other initializer for UIBarButtonItem. 注意:UIBarButtonItem还有其他一些初始化程序。 Choose any one as your need. 根据需要选择任何一个。

Hope this helps.. :) 希望这可以帮助.. :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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