如何更改 "back" 栏按钮项的标题?
How to change the title of the "back" bar button item?
我想在不更改根视图控制器标题的情况下将 "Root View Controller" 后退按钮更改为 "Back"。
我已经尝试了这 3 个代码,但它们都不起作用。
navigationItem.backBarButtonItem?.title = "Back"
navigationItem.leftBarButtonItem?.title = "Back"
navigationItem.backBarButtonItem?.title = "Back"
我可以知道我做错了什么吗?
提前致谢。
这里是整个方法的代码,供大家参考:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
navigationItem.backBarButtonItem?.title = "Back"
navigationItem.leftBarButtonItem?.title = "Back"
manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
if activePlace == -1
{
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
}
else
{
// print( "String(myvar3.dynamicType) -> \(places[activePlace]["lat"].dynamicType)")
let latitude = Double(places[activePlace]["lat"]!)
let longitude = Double(places[activePlace]["lon"]!)
//creating map region and annotation
createMapRegionAndAnnotation(latitude!, longitude: longitude!)
print(latitude)
}
尝试覆盖之前的屏幕转场
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let backItem = UIBarButtonItem()
backItem.title = "My title"
navigationItem.backBarButtonItem = backItem
}
你也可以通过更改前一个视图控制器的导航项中的后退按钮属性从情节提要中更改它,如下所示:
在 child 中查看这对我有用;
self.navigationController!.navigationBar.topItem!.title = "Back"
这对我有用
let backItem = UIBarButtonItem()
backItem.title = ""
self.navigationItem.backBarButtonItem = backItem
我想在不更改根视图控制器标题的情况下将 "Root View Controller" 后退按钮更改为 "Back"。
我已经尝试了这 3 个代码,但它们都不起作用。
navigationItem.backBarButtonItem?.title = "Back"
navigationItem.leftBarButtonItem?.title = "Back"
navigationItem.backBarButtonItem?.title = "Back"
我可以知道我做错了什么吗? 提前致谢。
这里是整个方法的代码,供大家参考:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
navigationItem.backBarButtonItem?.title = "Back"
navigationItem.leftBarButtonItem?.title = "Back"
manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
if activePlace == -1
{
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
}
else
{
// print( "String(myvar3.dynamicType) -> \(places[activePlace]["lat"].dynamicType)")
let latitude = Double(places[activePlace]["lat"]!)
let longitude = Double(places[activePlace]["lon"]!)
//creating map region and annotation
createMapRegionAndAnnotation(latitude!, longitude: longitude!)
print(latitude)
}
尝试覆盖之前的屏幕转场
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let backItem = UIBarButtonItem()
backItem.title = "My title"
navigationItem.backBarButtonItem = backItem
}
你也可以通过更改前一个视图控制器的导航项中的后退按钮属性从情节提要中更改它,如下所示:
在 child 中查看这对我有用;
self.navigationController!.navigationBar.topItem!.title = "Back"
这对我有用
let backItem = UIBarButtonItem()
backItem.title = ""
self.navigationItem.backBarButtonItem = backItem