使用Swift中的hidesBackButton隐藏导航栏中的后退按钮 [英] Hide back button in navigation bar with hidesBackButton in Swift

查看:95
本文介绍了使用Swift中的hidesBackButton隐藏导航栏中的后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在从一个视图转换到另一个视图时隐藏后退按钮。我阅读了有关此问题的问题,每个答案都是使用 hidesBackButton 。这个问题是:

I want to hide the back button when transitioning from one view to another. I read the questions regarding this problem and every answer was "use hidesBackButton". The problem with this is:


  • 当我把它放在viewDidLoad / viewWillAppear后面的后退按钮箭头隐藏但字符串Back没有。

  • when I put it in viewDidLoad/viewWillAppear the back button arrow hides but the string "Back" doesn't.

当我把它放在viewDidAppear中时,后退按钮消失但对用户可见

when I put it in viewDidAppear the back button disappears but it visible to the user

我该如何解决这个问题?

How can I fix this?

编辑:

以下是如何复制此问题(或错误) ?)

在Xcode中使用Swift创建一个新的Tabbed应用程序。在FirstViewController.swift中,使用performSegueWithIdentifier导航到第二个视图控制器。在SecondViewController.swift中使用hidesBackButton隐藏导航栏后退按钮,你会看到问题所在。

Here is how you can replicate this problem(or bug?)
Make a new Tabbed application with Swift in Xcode. In the FirstViewController.swift use performSegueWithIdentifier to navigate to the second view controller. In the SecondViewController.swift hide the navigation bar back button using hidesBackButton and you will see what the problem is.

推荐答案

尝试添加这个:

let backButton = UIBarButtonItem(title: "", style: .Plain, target: navigationController, action: nil)
navigationItem.leftBarButtonItem = backButton

这篇关于使用Swift中的hidesBackButton隐藏导航栏中的后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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