xcode 左栏按钮项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43254254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:53:25  来源:igfitidea点击:

Left bar button Item

swiftxcodeuinavigationbaruibarbuttonitembackbarbuttonitem

提问by Mikael Weiss

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?

因此,如果您有一个没有条形按钮项的导航控制器,那么导航后退按钮将显示最后一个视图控制器的名称,我想保留它,因为我不想对其进行硬编码。而且我确实知道如何添加它,但我不想这样做,因为这会为错误留下更多空间。有没有办法让我有一个左栏按钮 Item 而默认的按钮不会消失?

回答by RajeshKumar R

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

在 viewController 中添加它,您希望在其中拥有默认后退按钮和自定义栏按钮项。您可以自定义条形按钮项。

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]
}