ios iOS如何删除后退按钮?

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

iOS how to remove back button?

iosnavigationcontroller

提问by jbearden

I have an application with a navigation bar that pushes to a login screen view controller and then pushes to a main menu. Is there any way I can remove the back button off the main menu, so the user is unable to go back to the login screen?

我有一个带有导航栏的应用程序,它推送到登录屏幕视图控制器,然后推送到主菜单。有什么办法可以从主菜单中删除后退按钮,使用户无法返回登录屏幕?

Thanks!

谢谢!

EDIT: Using Xcode 4.3 and doing all the leg work programmatically.

编辑:使用 Xcode 4.3 并以编程方式完成所有腿部工作。

回答by Peter Sarnowski

You can do:

你可以做:

[self.navigationItem setHidesBackButton:YES];

In your second view controller (the one you want to hide the button in).

在你的第二个视图控制器(你想隐藏按钮的那个)中。

回答by LJ Wilson

Peters answer is correct, although I think the better question is why? In a schema like yours where you are wanting to login a user, instead of using a Pushed VC, present a Modal VC and use a delegate method to get back the userinfo that was obtained in the Login process. I can post a complete code example if you need it, but it sounds like you have the details worked out with your login process. Just use:

彼得斯的回答是正确的,尽管我认为更好的问题是为什么?在像您这样的架构中,您想要登录用户,而不是使用 Pushed VC,而是呈现一个 Modal VC 并使用委托方法来取回在登录过程中获得的用户信息。如果您需要,我可以发布完整的代码示例,但听起来您已经在登录过程中制定了详细信息。只需使用:

presentModalViewController

instead of:

代替:

pushViewController

That way, you don't have to worry about the navigation stack and doing something that isn't really in-line with the user interface guidelines.

这样,您就不必担心导航堆栈和做一些与用户界面指南不符的事情。

回答by Hamzah Malik

In swift

在迅速

self.navigationItem.hidesBackButton = true

回答by Yoga

The above code did not work for me. As suggested in UINavigationItem setHidesBackButton:YES won't prevent from going back, I had to use:

上面的代码对我不起作用。正如UINavigationItem setHidesBackButton:YES 中所建议的那样不会阻止返回,我不得不使用:

[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] init]]];

回答by Flaviano Gomes

Try this:

尝试这个:

[self.navigationItem setHidesBackButton:YES];

Or

或者

[self.navigationItem setHidesBackButton:YES animated:YES];

回答by Codingpan

Tried in Xcode7.3.1, swift

在Xcode7.3.1中试过,迅速

self.navigationItem.setHidesBackButton(true, animated: true)

It only hide the back arrow and disabled the back action, but I can still see the name of the previous view controller.

它只隐藏后退箭头并禁用后退动作,但我仍然可以看到前一个视图控制器的名称。

For those who want to also hide the name of the previous view controller, try Yoga's answerworks for me. In swift

对于那些还想隐藏前一个视图控制器名称的人,试试Yoga 的答案对我有用。在迅速

self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: UIView())