iphone - 重命名表格 View 中的标准 "edit"按钮

标签 iphone uitableview

我设法(经过大量的试验和错误)让我的表格 View 提供重新排序功能,即我的表格 View 是可编辑的,但不显示“删除图标”,也不在单击时缩进行编辑按钮。

现在我希望按钮显示“排序”而不是“编辑”。

我天真地尝试了这个:

self.navigationItem.leftBarButtonItem = self.editButtonItem;
self.navigationItem.leftBarButtonItem.title = @"Sort";

它只能工作一次,即它被正确标记为“排序”,一旦单击它就会重命名为“完成”,但随后——正如预期的那样——它会重新命名为“编辑”。

为了解决这个问题,我在导航栏上部署了我的“自己的”按钮。这个解决方案有效 - 我可以使用按钮来控制表格 View 编辑模式,在更改时重新加载数据,重命名自身等 - 但我无法让它“保持突出显示”,即“编辑”按钮的默认行为在表格 View 中。

现在我的问题是:

a) 有没有办法重命名(并保持重命名,例如通过回调)标准的“编辑”按钮?

b)有没有办法让按钮“模态”运行,即保持选中状态,就像标准的“编辑”按钮一样?

感谢您的任何想法。

最佳答案

您可以将更改放入 View Controller 中的 - (void) setEditing:(BOOL)editingAnimated:(BOOL)animated 方法中。

- (void) setEditing:(BOOL)editing animated:(BOOL)animated {
    //Do super before, it will change the name of the editing button
    [super setEditing:editing animated:animated];

    if (editing) {
      self.navigationItem.leftBarButtonItem.title = @"Done";
      self.navigationItem.leftBarButtonItem.style = UIBarButtonItemStyleDone;
    }
    else {
      self.navigationItem.leftBarButtonItem.title = @"Sort";
      self.navigationItem.leftBarButtonItem.style = UIBarButtonItemStyleBordered;
    }
}

关于iphone - 重命名表格 View 中的标准 "edit"按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2020716/

相关文章:

iphone - 核心数据`deleteObject:`问题!

iphone - iPhone用户联系信息

ios - 在 iOS7 中使用 UISearchBar 向 tableHeaderView 添加 subview 行为不当

ios - 如何在 UITableViewController 中使用表格部分创建分页

ios - UITableViewCell iOS 中的 HTML 特殊字符

ios - 如何更新 UITableView 单元格文本字段中的核心数据值

ios - 如何修改 iPhone plist 以添加另一个级别并在代码中访问数据

iphone - 如何限制iOS应用内存使用

ios - 表格 View 上的背景点击

iphone - iOS:使用父类(super class)的 getter 和 setter 的属性不再适用于 Xcode 4.4