xcode 没有“返回”按钮的导航控制器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9174809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:15:07  来源:igfitidea点击:

Navigation Controller without a "Back" button

iosxcodeuinavigationcontrolleruinavigationbarsegue

提问by Eugene Trapeznikov

In my app i got view, where user adds new object, then he clicks on the "save" button and goes to main view. But after that we see "back" button on the main view. Can i do this segue (new object -> main window) without "back" button?

在我的应用程序中,我看到了用户添加新对象的视图,然后他单击“保存”按钮并转到主视图。但之后我们会在主视图上看到“返回”按钮。我可以在没有“后退”按钮的情况下执行此转场(新对象 -> 主窗口)吗?

回答by Sanjeev Rao

If you are navigating from VC1 to VC2. If you want hide back button when you goto VC2.

如果您从 VC1 导航到 VC2。如果您想在转到 VC2 时隐藏后退按钮。

Just write this in VC2

只需在VC2中写这个

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.navigationItem.hidesBackButton = YES;
    }
    return self;
}

OR

或者

- (id)init
{
    self = [super init];
    if (self) {
        self.navigationItem.hidesBackButton = YES;
    }
    return self;
}

回答by Nicole S

In case anyone else is having trouble getting this to work,

万一其他人在使用它时遇到问题,

'self.navigationItem.hidesBackButton = YES;'

'self.navigationItem.hidesBackButton = YES;'

didn't work for me when placed in

放入时对我不起作用

'- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil'.

'- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil'.

I moved it to '- (void)viewDidLoad'and it now works perfectly. I'm using Xcode 4.5.2.

我把它移到了'- (void)viewDidLoad',现在它可以完美运行。我正在使用 Xcode 4.5.2。

回答by Erik Aigner

Set self.navigationItem.hidesBackButton = YESon the pushed view controller.

self.navigationItem.hidesBackButton = YES在推送的视图控制器上设置。

回答by Krrish

- (IBAction)done:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

Then connect it to a button.

然后将其连接到按钮。