覆盖导航堆栈中的后退按钮,同时保持默认后退按钮的外观? [英] Override back button in navigation stack while keeping appearance of default back button?

查看:92
本文介绍了覆盖导航堆栈中的后退按钮,同时保持默认后退按钮的外观?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅覆盖一个视图的后退按钮(不适用于不同视图中的所有后退按钮),以便在单击后退按钮时显示根视图控制器。

How do I override the back button for just one view (not for all the back buttons present in different views) such that on click of the back button, root view controller is shown.

推荐答案

您需要替换后退按钮并关联动作处理程序:

You need to replace the backbutton and associate an action handler:

- (void)viewDidLoad {
    [super viewDidLoad];

    // change the back button to cancel and add an event handler
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"back"
                                                                   style:UIBarButtonItemStyleBordered
                                                                  target:self
                                                                  action:@selector(handleBack:)];

    self.navigationItem.leftBarButtonItem = backButton;
}

- (void)handleBack:(id)sender {
    // pop to root view controller
    [self.navigationController popToRootViewControllerAnimated:YES];
}

这篇关于覆盖导航堆栈中的后退按钮,同时保持默认后退按钮的外观?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆