4

I have a parent table view with custom rows, each one pushes a view controller with a tableview of selectable options that are stored as properties of the parent view controller. My code:

- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
  /*
    CrewPositions *selectedPosition = (self.crewPositionList)[indexPath.row];
    [self.delegate childCrewPositionDidSelect:selectedPosition];
    NSLog(@"child Selected Position: %@", selectedPosition.title);
    [[self navigationController] popViewControllerAnimated:YES];
  */
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    CrewPositions *selectedPosition = (self.crewPositionList)[indexPath.row];
    self.selectedCrewPosition = selectedPosition;
    NSLog(@"self.selectedCrewPosition: %@", self.selectedCrewPosition);
    selectedFlightHistory.crewPosition = selectedPosition;
    NSLog(@"self.selectedFlightHistory.crewPosition: %@", selectedFlightHistory.crewPosition.title);

    [self.delegate childCrewPositionDidSelect:selectedPosition];

    NSLog(@"Popping view to parent");
    [self.navigationController popViewControllerAnimated:YES];
}

works properly, unfortunately the method didSelectRowAtIndexPath does not get called until after I tap the list of cells a 2nd time. When I do, it passes the first row, previously selected, to the parent view. Ignore the copious amounts of NSLog, just capturing what the variables are doing.

Saqib Omer
  • 4,917
  • 7
  • 46
  • 65
Hawk_Pilot
  • 135
  • 2
  • 8

2 Answers2

9

rename your didDeselectRowAtIndexPath method to didSelectRowAtIndexPath

it is called on 2nd time because your select another cell and deselect the previous one

Bryan Chen
  • 42,570
  • 18
  • 109
  • 136
2

It's happening because you wrote wrong method name. didDeselectRowAtIndexpath: is sent when the row is de -selected.

So change the method name didSelectRowAtIndexPath: So that the implementation is for the correct delegate method.

Abizern
  • 129,329
  • 36
  • 198
  • 252
Mohit
  • 3,478
  • 2
  • 25
  • 30