重命名标准“编辑” tableview中的按钮 [英] Rename standard "edit" button in tableview

查看:202
本文介绍了重命名标准“编辑” tableview中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我管理(有大量的试验和错误)让我的tableview提供重新排序功能,即我的tableview是可编辑的,但不会显示删除图标,也不会在点击时缩进行编辑按钮。

I managed (with lots of trial and error) to have my tableview provide only reordering functionality, i.e. my tableview is editable but does not display "delete icons" nor indents the rows upon clicking on the edit button.

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

Now I would like the button to read "sort" instead of "edit".

我天真地试过这个:

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

只运行一次,即它被正确标记为排序,一旦点击它重命名为完成 ,但随后 - 正如预期的那样 - 它重新命名为编辑。

which works only once, i.e. it is correctly labeled "Sort", once clicked it renames to "Done", but then--as expected--it re-renames to "Edit".

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

In order to fix this, I deployed my "own" button on the navbar. This solution works--I can get the button to control the tableview editing mode, reload the data upon change, rename itself, etc--but I cannot get it to "stay highlighted", i.e. the default behaviour of the "Edit" button in a tableview.

现在我的问题是:

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

a) Is there a way to rename (and keep it renamed, e.g. through a callback) the standard "Edit" button?

b)是有一种方法让一个按钮表现为模态,即保持选中状态,如标准的编辑按钮?

b) Is there a way to have a button behave "modally", i.e. stay selected, like the standard "Edit" button?

感谢您的任何想法。

推荐答案

您可以将更改放在 - (void)setEditing:(BOOL)编辑动画:(BOOL)视图控制器中的动画方法。

You can put your changes in the - (void) setEditing:(BOOL)editing animated:(BOOL)animated method in your view controller.

- (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;
    }
}

这篇关于重命名标准“编辑” tableview中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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