如何在不覆盖自然后退按钮的情况下添加左栏按钮? [英] How do I add a left bar button without overriding the natural back button?

查看:94
本文介绍了如何在不覆盖自然后退按钮的情况下添加左栏按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,该项目使用嵌入在导航视图控制器中的UIViewControllers,因此每当我搜索到我的表视图的任何细节时,都会自动为我设置后退按钮.

I have a project that uses UIViewControllers embedded in navigation view controllers, so the back button is automatically set up for me whenever I segue into any detail of my tableviews.

现在,我想在后退"按钮旁边添加一个编辑"按钮.我已经在右侧放置了一个取消分配"按钮,并且由于"Unassign"一词很长,所以我宁愿将编辑"按钮放在左侧的后退"按钮旁边.

Now I want to add an Edit button beside the back button. I've already put an Unassign button on the right side, and since the word "Unassign" is quite long, I'd rather fit the Edit button beside the back button on the left side.

我知道我可以使用navigationItem.leftBarButtonItem = editButton以编程方式添加条形按钮,但这会覆盖后退按钮.

I know I can programmatically add bar buttons with navigationItem.leftBarButtonItem = editButton but that overrides the back button.

我也尝试过将editButton附加到navigationItem.leftBarButtonItems数组,但这也行不通(因为首先没有设置leftBarButtonItems数组).

I've also tried appending the editButton to the navigationItem.leftBarButtonItems array, but that doesn't work too (since the leftBarButtonItems array isn't set in the first place).

我的下一个方法是找到后退按钮并将其手动添加到leftBarButtonItems数组中,因此我尝试使用navigationItem.leftBarButtonItems = [self.navigationItem.backBarButtonItem!, editButton],但这仅在editButton和左侧之间添加了一个空格.没有后退按钮.

My next approach was to find the back button and manually add it to the leftBarButtonItems array, so I tried using navigationItem.leftBarButtonItems = [self.navigationItem.backBarButtonItem!, editButton], but that only adds a space between the editButton and the left side. No back button.

如何在不改变后退按钮的情况下添加左栏按钮?有没有比用self.navigationController?.popViewControllerAnimated(true)手动编码一个新的后退按钮并将其添加到leftBarButtonItems数组更好的方法了?

How do I add in a left bar button while leaving the back button untouched? Is there a more elegant way than manually coding a new back button with self.navigationController?.popViewControllerAnimated(true) and adding it to the leftBarButtonItems array?

推荐答案

默认情况下,leftItemsSupplementBackButton属性为false.在这种情况下, 没有绘制后退按钮,而是用一个或多个左项目替换了它.如果你 希望将除后退"按钮(而不是代替按钮)之外的其他左项显示为leftItemsSupplementBackButtontrue.

By default, the leftItemsSupplementBackButton property is false. In this case, the back button is not drawn and the left item or items replace it. If you would like the left items to appear in addition to the back button (as opposed to instead of it) set leftItemsSupplementBackButton to true.

@property(nonatomic) BOOL leftItemsSupplementBackButton

您可以使用类似的东西

navigationItem.leftBarButtonItem = editButton
//or
navigationItem.leftBarButtonItems = [editButton]

self.navigationItem.leftItemsSupplementBackButton = true

这篇关于如何在不覆盖自然后退按钮的情况下添加左栏按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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