2013-02-23 67 views
1

我正在使用我的导航工具栏中的Edit按钮将表视图设置为编辑模式。酒吧按钮的标签默认为EditUITableView:重命名编辑按钮(UIBarButtonSystemItemEdit)

如何将其标签更改为其他内容?

我不能使用任何其他类型的BarButton,因为我需要设置表中的编辑模式,我希望得到setEditing:animated:行为是由触发内置Edit按钮。

self.editToolbarButton = [[UIBarButtonItem alloc] 
    initWithBarButtonSystemItem:UIBarButtonSystemItemEdit 
    target:self action:@selector(setSearchEditMode:)]; 

回答

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 
} 
相关问题