左栏按钮项目 [英] Left bar button Item

查看:95
本文介绍了左栏按钮项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,如果您有一个没有条形按钮项目的导航控制器,那么将显示一个导航后退按钮,并带有最后一个View Controller的名称,我想保留该名称,因为我不想对它进行硬编码.而且我确实知道如何添加它,但是我不想这样做,因为这为错误留出了更多的空间.有没有一种方法可以让我有一个左栏按钮Item,而默认按钮不会消失?

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?

推荐答案

在要拥有默认后退按钮和自定义条形按钮项的viewController中添加此代码.您可以自定义条形按钮项目.

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

这篇关于左栏按钮项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆