iOS中的backBarButtonItem(Swift)

var backButton: UIBarButtonItem = UIBarButtonItem(title: "CUSTOM", style: UIBarButtonItemStyle.Bordered, target: self, action: nil) newNavigationItem.backBarButtonItem = backButton 

newNavigationItem: UINavigationItem在哪里newNavigationItem: UINavigationItem

我想要自定义标题。 它显示“返回”文本或“最后一个视图的标题”。 所以这是行不通的。 为什么?

Yogesh Suthar说的方法将取代整个后退button,所以你不会有默认的左箭头符号! 我build议使用这个代码:

 navigationController?.navigationBar.topItem?.backBarButtonItem = backButton 

使用leftBarButtomItem

 newNavigationItem.backBarButtonItem = backButton 

应该

 newNavigationItem.leftBarButtonItem = backButton 
 override func viewDidLoad() { super.viewDidLoad() let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "backAction") navigationController?.navigationBar.topItem?.backBarButtonItem = newBackButton 

}

 func backAction() -> Void { self.navigationController?.popViewControllerAnimated(true) }