我想将"Root View Controller"后退按钮更改为"Back"而不更改Root View Controller的标题.
我已经尝试了这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) }
Oleg Gordiic.. 10
尝试覆盖以前的屏幕segue
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let backItem = UIBarButtonItem() backItem.title = "My title" navigationItem.backBarButtonItem = backItem }
@TeeMingWei如果要为当前视图控制器的导航项设置后退按钮,则不会设置在当前视图中显示的按钮.实际上,如果从其中推送另一个视图控制器,则设置将使用的后退按钮. (2认同)
Ajinkya Pati.. 5
您还可以通过更改前一个视图控制器的导航项中的后退按钮属性,从情节提要中更改它,如下所示:
尝试覆盖以前的屏幕segue
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let backItem = UIBarButtonItem() backItem.title = "My title" navigationItem.backBarButtonItem = backItem }
您还可以通过更改前一个视图控制器的导航项中的后退按钮属性,从情节提要中更改它,如下所示: