如何在NavigationBar上更改BarButtonItem的文本? [英] How to change the text of a BarButtonItem on the NavigationBar?

查看:139
本文介绍了如何在NavigationBar上更改BarButtonItem的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建可以编辑的项目列表。这样的事情:

I am trying to create a list of items that can be edited. Something like this:

为此,我在视图顶部添加了一个NavigationBar,然后在XCode设计器中添加了2个Bar Button项目。我将左侧按钮的标识符设置为Add,右侧的按钮设置为Edit。

To that end, I added a NavigationBar to the top of the view, then added 2 Bar Button Items in XCode designer. I set the identifier for the button on the left to Add, for the button on the right to Edit.

当我单击编辑时,我想将文本更改为完成。我尝试了各种方法,例如 btnEdit.Title =完成,但它根本不需要。

When I click the Edit, I want to change the text to Done. I've tried various ways, e.g. btnEdit.Title = "Done", but it simply doesn't take.

我看过几篇推荐.SetTitle的博文,但UIButtonBarItem没有这种方法(至少在MonoTouch中)。

I've seen several blog posts recommending .SetTitle, but UIButtonBarItem doesn't have that method (at least in MonoTouch).

那么,如何更改编辑按钮的标题?

So, how can I change the title of the Edit button?

推荐答案

我解决了。关键是我将Edit按钮的标识符设置为系统值(例如UIBarButtonSystemItemEdit),你无法更改那些文本(现在有意义)。我将标识符更改回自定义并设置。标题工作正常。

I resolved it. The key was I was setting the identifier of the Edit button to a system value (e.g. UIBarButtonSystemItemEdit) and you can't change the text of those (makes sense now). I changed the identifier back to Custom and setting .Title worked fine.

这篇关于如何在NavigationBar上更改BarButtonItem的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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