左栏按钮项 - 显示前一个视图控制器的名称 [英] Left Bar Button Item - show name of previous View Controller

查看:14
本文介绍了左栏按钮项 - 显示前一个视图控制器的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有一个没有 Bar Button Items 的导航控制器,一个导航后退按钮将显示为最后一个视图控制器的名称.

If you have a Navigation Controller with no Bar Button Items, a navigation back button will be shown with the name of the last View Controller.

我想保留那个名字,因为我不想硬编码它.我确实知道如何添加它,但我不想这样做,因为这会为错误留下更多空间.

I want to keep that name, as in I don't want to have to hardcode it. 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.

有没有办法让我拥有一个左侧的 Bar Button Item 而默认的 Bar Button 不会消失?

Is there a way that I can have a left Bar Button Item and for the default one to not 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天全站免登陆