作者:能然然520 | 来源:互联网 | 2023-05-25 15:22
我想在从一个视图转换到另一个视图时隐藏后退按钮.我读了关于这个问题的问题,每个答案都是"使用hidesBackButton
".这个问题是:
当我把它放在viewDidLoad/viewWillAppear时,后退按钮箭头隐藏但字符串"Back"没有.
当我把它放在viewDidAppear中时,后退按钮消失但对用户可见
我怎样才能解决这个问题?
编辑:
以下是如何复制此问题(或错误?)
在Xcode中使用Swift创建一个新的Tabbed应用程序.在FirstViewController.swift中,使用performSegueWithIdentifier导航到第二个视图控制器.在SecondViewController.swift中使用hidesBackButton隐藏导航栏后退按钮,您将看到问题所在.
1> ObjectiveTC..:
使用最新的Swift隐藏后退按钮:
self.navigationItem.setHidesBackButton(true, animated: false)
2> ericgu..:
尝试添加此:
let backButton = UIBarButtonItem(title: "", style: .Plain, target: navigationController, action: nil)
navigationItem.leftBarButtOnItem= backButton
我们知道为什么`hidesBackButton`不仅隐藏"<"(而不是"
在swift 4中,样式现在应该是`.plain`
3> 小智..:
您可以使用下面的代码隐藏后退按钮UINavigationBar
.
斯威夫特3 ;
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationItem.hidesBackButton = true
}
4> luhuiya..:
这对我有用
navigationController?.navigationBar.topItem?.hidesBackButton = true
5> A.G..:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.navigationController?.navigatiOnBarHidden= false
var button: UIButton = UIButton()
button.setImage(UIImage(named: "person-icon.jpg"), forState: .Normal)
button.frame = CGRectMake(0, 0, 25, 25)
button.targetForAction("actioncall", withSender: nil)
var rightItem:UIBarButtOnItem= UIBarButtonItem()
rightItem.customView = button
self.navigationItem.rightBarButtOnItem= rightItem
let backButton = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: navigationController, action: nil)
navigationItem.leftBarButtOnItem= backButton
}
override func viewWillAppear(animated: Bool) {
let backButton = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: navigationController, action: nil)
navigationItem.leftBarButtOnItem= backButton
}
6> Ha cong Thua..:
尝试添加这个,这对我有用
navigationItem.hidesBackButton = true