tags:

views:

78

answers:

3

Hello

I have a TableView on my View. I somehow do not have a Navigation bar. I only have UIButtons and I want one of my buttons to do exactly what the editButtonItem.

How must I proceed to do that?

+1  A: 

add a target to that button – i.e.

@selector(editButtonPressed:)

Then in editButtonPressed: use the function

[self.tableView setEditing:YES animated:YES];

i think that'll work...

jmont
You may want to do `[self.tableView setEditing:!self.editing animated:YES]`, that way you can use one method to toggle back and forth between editing states.
Gordon Fontenot
okayasu
there are plenty of tutorials online. i.e.http://www.switchonthecode.com/tutorials/iphone-tutorial-creating-basic-buttonsgoogle is your friend.
jmont
Posted the code snippet as a separate answer for formatting reasons.
Gordon Fontenot
Thank you very much to both of you, i'll give a try tomorrow :D
okayasu
A: 

Where you create your button:

[myButton addTarget:self action:selector(toggleEditMode:) forControlEvents:UIControlEventTouchUpInside];

Then add the method:

-(void)toggleEditMode:(id)sender {
    // Change the tableview's editing state to the opposite of the current state
    [self.tableView setEditing:!self.editing animated:YES];

    // change the title of the button
    UIButton *editButton = (UIButton *)sender;
    if (self.editing) {
        [editButton setTitle:@"Done" forState:UIControlStateNormal];
    } else {
        [editButton setTitle@"Edit" forState:UIControlStateNormal];
    }
}
Gordon Fontenot
It works gordon :D
okayasu
thanks very much :p
okayasu
A: 

And how do we put it back to normal after??

okayasu
You should have edited your original question to ask this, but what do you mean "back to normal"? If you use the code I posted, it will put your tableview into editing mode, and then back again. It should also change the title of the button from "Edit" to "Done" and back again.
Gordon Fontenot
ok I'll try this tomorrow gordon, in fact i used your code but only with [self.tableView setEditing:!self.editing animated:YES]; :pthanks man :D
okayasu