我在导航工具栏中使用Edit
按钮将表格视图设置为编辑模式。条形按钮的标签默认为Edit
。
如何将其标签更改为其他内容?
我不能使用任何其他BarButton类型,因为我需要将表设置为编辑模式,我想获得由内置setEditing:animated:
按钮触发的Edit
行为
self.editToolbarButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
target:self action:@selector(setSearchEditMode:)];
答案 0 :(得分:2)
只需使用两个标签创建自己的按钮。
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:@"Title1" style: UIBarButtonItemStyleBordered target:self action:@selector(setSearchEditMode:)];
btn.possibleTitles = [NSSet setWithObjects:@"Title1", @"Title2", nil];
self.editToolbarButton = btn;
- (void)setSearchEditMode:(UIBarButtonItem *)button {
// Toggle the view controller's editing state
[self setEditing:!self.editing animated:YES];
// Update the button's title
button.title = self.editing ? @"Title2" : @"Title1";
// other processing
}