我有一个带有自定义行的父表视图,每个视图控制器都推送一个带有tableview
可选选项的视图控制器,这些选项存储为父视图控制器的属性。我的代码:
- (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];
}
工作正常,不幸的是,didSelectRowAtIndexPath
直到我第二次点击单元格列表之后,该方法才会被调用。当我这样做时,它将先前选择的第一行传递给父视图。忽略大量的NSLog
,只捕获变量在做什么。