Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone Storyboard Editing a table view

I've been trying to learn the new Storyboard feature in Xcode and I've run into a problem with trying to set a UITableView to edit mode.

So far my storyboard looks like this:

NavigationController -> UIViewController (subclass with tableview property)

I added a Navigation Item and a Bar Button item to the view controller scene, so I do see an edit button. It didn't do anything automagically, so I tried linking it's selector to the setEditing method of the tableview delegate. This did put it into editing mode. However, the edit button did not change to a "Done" button and so there is no way to get out of editing mode.

Do I have to create another Navigation item for the Done button? How do I connect it so that it appears at the right time and works correctly?

like image 355
markplee Avatar asked Oct 27 '11 19:10

markplee


People also ask

What is table View in iOS?

Overview. Table views in iOS display rows of vertically scrolling content in a single column. Each row in the table contains one piece of your app's content. For example, the Contacts app displays the name of each contact in a separate row, and the main page of the Settings app displays the available groups of settings ...


2 Answers

I think that also with Storyboard, the only way (for sure, the easiest one) to implement a working edit/done button, is to use the following code:

- (void)viewDidLoad
{
[super viewDidLoad];
...
//set the edit button
self.navigationItem.leftBarButtonItem = self.editButtonItem;
...

This is the solution that Apple itself implements if you select a "Master-Detail Application" template for your project.

Probably Storyboard is still not perfect, and hopefully it will be improved from Apple in next releases...

like image 76
yassassin Avatar answered Sep 26 '22 08:09

yassassin


I just started using Storyboards, so I also wanted to use the Storyboard to add my Edit button. It is annoying to have taken the time to learn how to use a new tool but find you need a roll of duct tape to patch up the holes.

You can get it to work, but need to add a Custom button. In the Attributes inspector make sure the Identifier is Custom and the title is Edit.

Then add something like this in your .m

- (IBAction)setEditMode:(UIBarButtonItem *)sender {
    if (self.editing) {
        sender.title = @"Edit";
        [super setEditing:NO animated:YES];
    } else {
        sender.title = @"Done";
        [super setEditing:YES animated:YES];
    } 
}

Have your Custom Edit button call the setEditMode method.

Can only hope they will fix the implementation of the Edit button in the Storyboard editor in the future.

like image 25
Graham Avatar answered Sep 23 '22 08:09

Graham