2

I have a simple table view that can segue to an update-view-contoller to edit that row when the user taps on a row. Issue: I would like to segue to the update-view-contoller when the table view is in "edit-mode", otherwise nothing should happen.

I am using Storyboard to create the segue linking the prototype cell to the update-view-controller.

Any idea on how to make the segue work only if the table view is in "edit-mode"?

Here is my prepare for segue code that is invoked when the user taps on a row from the table view contoller. My segue has an identerfied called "ShowUpdate":

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([[segue identifier] isEqualToString:@"ShowUpdate"]) {

        UpdateViewController *updateviewcontroller = [segue destinationViewController];

        NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];

        int row = [myIndexPath row];

        NSString *selectedRow = [NSString stringWithFormat:@"%d", row];

        updateviewcontroller.DetailModal = @[_Title[row], _Description[row], selectedRow];

    }

}

Thanks for any help

Martin Koles
  • 5,177
  • 8
  • 39
  • 59
user3424472
  • 55
  • 1
  • 8

1 Answers1

3

How about a simple if check for isEditing property of the tableView?

@property(nonatomic, getter=isEditing) BOOL editing

Instead of making a segue from a prototype cell, I would drag it from the ViewController itself, and then check the above property in the didSelectRowAtIndexPath: delegate method and perform the segue in code from there.

Plus, you would need to set allowSelectionDuringEditing property somewhere in viewDidLoad or so.

self.tableView.allowsSelectionDuringEditing = YES;

Code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.tableView.isEditing) {

    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    [self performSegueWithIdentifier:@"ShowUpdate" sender:cell];
    }
}

Segue construction:

enter image description here

Martin Koles
  • 5,177
  • 8
  • 39
  • 59
  • Hi, this suggestion works except that now the Done button does not work to exit EDIT-MODE? This line @property(nonatomic, getter=isEditing) BOOL editing; and this line self.tableView.allowsSelectionDuringEditing = YES; seem to make the DONE button not work. Do you happen to know if there is specific code needed to make the DONE but work to exit EDIT-MODE? Thank you very much :) – user3424472 Mar 21 '14 at 05:25
  • This line: @property(nonatomic, getter=isEditing) BOOL editing, is a copy from Apple's documentation. I used that to show the property of the tableView and that it has a different name for the getter. Just skip this line, don't include it in your code and the button will work. Sorry for the confusion. – Martin Koles Mar 21 '14 at 08:40