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.
rename your
didDeselectRowAtIndexPathmethod todidSelectRowAtIndexPathit is called on 2nd time because your select another cell and deselect the previous one