简体   繁体   English

禁用后退按钮并在导航视图控制器中放置取消按钮 - 就像联系人iPhone应用程序一样

[英]Disabling back button and put Cancel button in navigation view controller — like contacts iPhone application

I have a navigation view controller and there are 3 view controllers in the navigation stack. 我有一个导航视图控制器,导航堆栈中有3个视图控制器。 Now on the third and top most visible view controller I have a default back button coming in. 现在在第三个也是最可见的视图控制器上,我有一个默认的后退按钮。

I need to bring this view controller in edit mode which I did... Now the requirement is to have a cancel button as the left bar button item instead of back button. 我需要将这个视图控制器带入编辑模式,我做了...现在要求的是取消按钮作为左边的按钮项而不是后退按钮。

This is similar to the functionality given by contacts application of iPhone where you edit a particular contact. 这与您编辑特定联系人的iPhone的联系人应用程序提供的功能类似。

Any clue how to achieve this? 任何线索如何实现这一目标?

To hide back button and add a left bar button use- 要隐藏后退按钮并添加左侧按钮,请使用 -

[self.navigationItem setHidesBackButton:TRUE];

    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector()];
    [self.navigationItem setLeftBarButtonItem:leftBarButton];
    [leftBarButton release];

And then to programmatically return to the previous view controller, you can do- 然后以编程方式返回到上一个视图控制器,您可以 -

[self.navigationController popViewControllerAnimated:YES];

这是一种更简单的方法:

[self.navigationItem setHidesBackButton:YES];

If you are using storyboard, you can also just drag a bar button item onto the navbar where the back button would normally show up. 如果您正在使用故事板,您还可以将条形按钮项拖到导航栏上,后退按钮通常会显示在该导航栏上。 This will override it. 这将覆盖它。

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

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