Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何更改导航栏上BarButtonItem的文本?_Ios_Xamarin.ios_Uinavigationbar_Uibuttonbaritem - Fatal编程技术网

Ios 如何更改导航栏上BarButtonItem的文本?

Ios 如何更改导航栏上BarButtonItem的文本?,ios,xamarin.ios,uinavigationbar,uibuttonbaritem,Ios,Xamarin.ios,Uinavigationbar,Uibuttonbaritem,我正在尝试创建一个可以编辑的项目列表。大概是这样的: 为此,我在视图顶部添加了一个导航栏,然后在XCode designer中添加了两个栏按钮项。我为左边的按钮设置了要添加的标识符,为右边的按钮设置了要编辑的标识符 单击“编辑”时,我想将文本更改为“完成”。我尝试过各种方法,例如btnEdit.Title=“Done”,但根本不需要 我看过几篇推荐.SetTitle的博客文章,但UIButtonBarItem没有这种方法(至少在MonoTouch中是这样) 那么,如何更改编辑按钮的标题 对我来

我正在尝试创建一个可以编辑的项目列表。大概是这样的:

为此,我在视图顶部添加了一个导航栏,然后在XCode designer中添加了两个栏按钮项。我为左边的按钮设置了要添加的标识符,为右边的按钮设置了要编辑的标识符

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

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


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

对我来说就是这样的uibarbuttonite*btnEdit;是.h中的类成员

btnEdit = [[UIBarButtonItem alloc]initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(btnEditClicked)];
self.navigationItem.leftBarButtonItem = btnEdit;
//[btnEdit release];
现在被称为选择器的是:

-(void)btnEditClicked
{
  if([btnEdit.title isEqualToString:@"Edit"])
  {
    [btnEdit setTitle:@"Done"];
  }
  else
  {
    [btnEdit setTitle:@"Edit"];
  }
}

为什么不尝试更改
navigationItem.RightBarButtonim
属性

1。设置两个按钮,一个用于编辑,一个用于完成

 UIBarButtonItem*editButton=[[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(editAction)];

 UIBarButtonItem*doneButton=[[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(doneAction)];
2.必要时,在
editAction
中,最好更改
rightBarButtonItem
如下:

self.navigationItem.rightBarButtonItem=doneButton;
如果您需要返回
edit按钮

 self.navigationItem.rightBarButtonItem=editButton;

希望这有帮助。快乐编码:)

我解决了它。关键是我将编辑按钮的标识符设置为系统值(例如UIBarButtonSystemiteEdit),您无法更改这些按钮的文本(现在有意义)。我将标识符改回了自定义和设置。标题工作正常。

控制从工具栏按钮拖动到文件(使用辅助编辑器),创建插座(在本例中,它被称为“barButton”)。然后,添加以下内容:

Swift 3.0:

self.barButton.title = "New title"

重新按下按钮,如下所示

self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "title", style: UIBarButtonItemStyle.plain, target: self, action: #selector(actionMethod))

你不能用==来比较字符串。你应该用isEqualToString:来代替。如果答案有帮助,请接受它,以指导其他有同样问题的人。谢谢。真的很有帮助。谢谢:)天哪,我在这方面陷入了尴尬的长时间。。谢谢在更改
右侧按钮项时,由于某种原因,附加到两个按钮的操作都不起作用。
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "title", style: UIBarButtonItemStyle.plain, target: self, action: #selector(actionMethod))