1
votes

I do have a UITableViewController which can be edited. I do have 2 Segues in my Storyboard, coming from the tableView going to an EditViewController (via modal) and the second one via Push to the DetailViewController.

I want, when the tableview isEditing, that the segue to editviewcontroller is executed, and when is not editing, than to DetailViewController.

I tried different ways, with the prepareforsegue method. then several tries with the didselectrowatindexpath method, where I stand now.

Now, when the tableView is in editing and I touch one cell, the detailviewcontroller pushes and on top of this the editviewcontroller comes in as modal view controller.

Here is my code. Can you please give me hints:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"didSelectRowAtIndexPath %i", indexPath.row);
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (tableView.isEditing == FALSE) {
    NSLog(@"isediting");
    [self performSegueWithIdentifier:@"showDetail" sender:cell];
} else {
    [self performSegueWithIdentifier:@"showEditPerson" sender:cell];
}
}

and here is what i have tried with the prepare for segue method:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"showDetail"]) {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    NSDictionary *theChild = [myAppDelegate.myPersonsArray objectAtIndex:indexPath.row];
    [[segue destinationViewController] setDetailItem:theChild];
}
if ([[segue identifier] isEqualToString:@"showEditPerson"]) {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    NSDictionary *theChild = [myAppDelegate.myPersonsArray objectAtIndex:indexPath.row];
    [[segue destinationViewController] setDetailItem:theChild];
}
}
1
Is it possible you still have the segue hooked up to the prototype cell in the Storyboard file? Try putting breakpoints in prepareForSegue to see where it gets triggered from.Matt Martel
Hi Matt. Thanks a lot. You are right. I hooked up the TableViewCell to the DetailViewController and not the RoottableView to the DetailViewController. Thanks again! Yours, RaphaelRaphael

1 Answers

0
votes

From my comment above:

It seems you have the prototype cell hooked up to a segue in addition to the delegate method. Fix the segue connections and you should be all set.