4

我有一个带有自定义行的父表视图,每个视图控制器都推送一个带有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,只捕获变量在做什么。

4

2 回答 2

9

将您的didDeselectRowAtIndexPath方法重命名为didSelectRowAtIndexPath

第二次调用它,因为您选择另一个单元格并取消选择前一个单元格

于 2014-01-17T03:32:39.440 回答
2

发生这种情况是因为您编写了错误的方法名称。didDeselectRowAtIndexpath:取消选择行时发送。

所以更改方法名称didSelectRowAtIndexPath:以便实现是针对正确的委托方法。

于 2014-01-17T07:24:16.987 回答