Left bar button Item

◇◆丶佛笑我妖孽 提交于 2020-03-19 05:39:32

问题


so if you have a navigation controller with no bar button Items then a navigation back button will show up with the name of the last View Controller and I want to keep that, as in I don't want to have to hardCode it. and I do know how to add it in but I don't want to have to do that because that leaves more room for bugs. Is there a way that I can have a left bar button Item and the default one doesn't go away?


回答1:


Add this in viewController where you want to have default back button and custom bar button item. You can customise the bar button item.

override func viewDidLoad() {
    super.viewDidLoad()
    let newBtn = UIBarButtonItem(title: "new", style: .plain, target: self, action: #selector(anotherMethod))
    self.navigationItem.leftItemsSupplementBackButton = true
    self.navigationItem.leftBarButtonItem = newBtn//self.navigationItem.leftBarButtonItems = [newBtn,anotherBtn]
}


来源:https://stackoverflow.com/questions/43254254/left-bar-button-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!