快速更改按钮标题后的后退按钮标题
问题描述:
我有一个有一些后退标题“XYZ”的VC,在viewDidLoad中,我将它更改为“ABC”。然后我想用相同的方法再次更改它,但它不起作用。尝试了很多解决方案,但没有成功。快速更改按钮标题后的后退按钮标题
我找到了这段代码。在viewdidload中唤醒......但在此之后它不。
let backButton = UIBarButtonItem(
title: " ",
style: UIBarButtonItemStyle.Plain,
target: nil,
action: nil
)
self.navigationController!.navigationBar.topItem!.backBarButtonItem = backButton
答
在UIViewController
类执行此操作。这会留下后退箭头,但会移除旁边的文字。
private var _title: String?
var backBarButtonHidden: Bool {
didSet {
if let index = navigationController?.viewControllers.indexOf(self) {
if index > 0 {
if let button = navigationController?.navigationBar.items?[index - 1] {
if backBarButtonHidden {
_title = button.title
button.title = ""
} else { button.title = _title }
}
}
}
}
那么这工作时,我不添加我的一段代码在viewdidload。但是,我无法再将标题添加到按钮。 : -/ –
是的,你可以,你将不得不存储在一个私人变量的标题,并以完全相同的方式访问标题: –
啊哈....哇现在这是我想要的:-)非常感谢你。你让我很开心:-) –