views:

291

answers:

1

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".

I naively tried this:

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".

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.

Now my question is either:

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

or

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

Thanks for any idea you might have.

+4  A: 

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 if {
      self.navigationItem.leftBarButtonItem.title = @"Sort";
      self.navigationItem.leftBarButtonItem.style = UIBarButtonItemStyleBordered;
    }
}
gcamp
Works like a charm (and answers my question). Thanks!
Roberto Brega