views:

838

answers:

3

I have a TableView that I want to change to a different view (View1) for editing the data for that row when editing is true. When editing is not true I use the didSelectRowAtIndexPath to change to a different view(View2) loading the information from the selected row.

An example of this is if you go to the built in clock select alarm, select edit then select an alarm(assuming you have at least one) you are then taken to the edit alarm screen but only if you are in edit.

So my question is how do I replicate this functionality while in edit.

A: 

You can keep track of whether or not you're currently in edit mode, clicking the edit button puts you in edit mode, clicking cancel takes you out of edit mode.

When going into edit mode push another nav item on the nav bar with the cancel button, when leaving edit mode pop the nav item.

The cells can be displayed with different content depending on if you are in edit mode or not. When switching in or out of edit mode reload the table data, will cause the different display.

didSelectRowAtIndexPath can have different behavior depending on whether or not you are in edit mode. If a cell is clicked while in edit mode bring up your edit view, if not in edit mode change to your View2.

jan
I guess my real question then is how do I know I am in edit, that is what I can't figure out.
Greg
I do something kind of similar to this, changing content while in the same view, and either use a BOOL if only two view or NSInteger for multiple views to determine which content to display.
jan
A: 

In your UITableViewDelegate there is an optional method:

tableView:willBeginEditingRowAtIndexPath:

This method only notifies you if the user swipes the cell. To know you are in edit mode through any other method (ie button press) you could use:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"Editing");
    isEditing = YES;        

    return UITableViewCellEditingStyleDelete;
}

Note that you have to return a UITableViewCellEditingStyle, in most cases this will be UITableViewCellEditingStyleDelete. Also note that this is called for each cell so if you only wish to check if you are in editing mode (as opposed to being notified) you can use:

[tableView isEditing]
bmalicoat
Thanks this is what I was missing. I used the [tableView isEditing] to determine which screen the row selection takes you too.
Greg
A: 

As far as knowing whether you're in edit mode, UITableView has a property editing to do just that, as well as an appropriate animated setter. (The system will also toggle your Edit/Done button according to this state, if you use the right button type.)

Sixten Otto