xcode 如何从导航栏中删除后退按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10882198/
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-15 00:29:41  来源:igfitidea点击:

How to remove back button from navigation bar

objective-ciosxcode

提问by Radislav

I have that code. It can add edit button to navigatin bar, but back button still exists, but it becomes unresponsible.

我有那个代码。它可以在导航栏中添加编辑按钮,但返回按钮仍然存在,但它变得不负责任。

UIBarButtonItem *editButton = [[UIBarButtonItem alloc] 
                               initWithTitle:@"Edit"                                            
                               style:UIBarButtonItemStyleBordered 
                               target:nil 
                               action:nil];
[[self.navigationController.navigationBar.items objectAtIndex:1] setRightBarButtonItem:editButton];

[[self.navigationController.navigationBar.items objectAtIndex:1]setHidesBackButton:YES];

回答by CarlJ

simply and short:

简单而简短:

  self.navigationItem.backBarButtonItem = nil;

or

或者

  self.navigationItem.leftBarButtonItem = nil;

回答by Paresh Navadiya

I have done something similar to this before. In the controller that's going to push the next view controller that you don't want a back button in put this wherever you're doing your pushViewController:

我以前做过类似的事情。在将要推送下一个您不想要后退按钮的视图控制器的控制器中,将它放在您执行 pushViewController 的任何位置:

 myNextViewController.navigationItem.hidesBackButton = YES;
 [self.navigationController pushViewController:myNextViewController animated:YES];

回答by Peter Cetinski

You can also use

你也可以使用

Objective-C:

目标-C:

self.navigationItem.hidesBackButton = YES;

Swift:

迅速:

navigationItem.hidesBackButton = true

回答by Shehzad Bilal

Either of these will work

这两个都行

self.navigationItem.leftBarButtonItem = nil;

or

或者

self.navigationItem.backBarButtonItem = nil;

回答by CWineland

This is old but after reading this today the answer of:

这是旧的,但今天读完这篇文章后,答案是:

self.navigationItem.hidesBackButton = YES;

is correct but is incomplete, this needs to be done at a later life cycle method then viewDidLoad, aka toss it in viewWillApper or something later and it will work

是正确的但不完整,这需要在以后的生命周期方法中完成,然后 viewDidLoad,也就是将它扔到 viewWillApper 或稍后的东西中,它会起作用

- (void)viewWillAppear:(BOOL)animated{
    self.navigationItem.hidesBackButton = YES;
}

Hope this helps someone looking at an old post as I did today

希望这可以帮助像我今天一样看旧帖子的人