【问题标题】:why does my tableview not call didselectrowatindexpath until 2nd touch? [duplicate]为什么我的 tableview 直到第二次触摸才调用 didselectrowatindexpath? [复制]
【发布时间】:2014-02-06 06:39:20
【问题描述】:

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

【问题讨论】:

  • 是的 - 如果您阅读您正在实现的委托方法的名称,它会有所帮助。

标签: ios objective-c uitableview popviewcontrolleranimated


【解决方案1】:

将您的 didDeselectRowAtIndexPath 方法重命名为 didSelectRowAtIndexPath

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

【讨论】:

  • 天哪,我是瞎子!
  • 你不是第一个犯这个错误的人......
  • 你不会是最后一个 - (免责声明 - 我已经做过几次了)
【解决方案2】:

这是因为你写错了方法名。 didDeselectRowAtIndexpath: 在行被 de 选中时发送。

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

【讨论】:

  • 不要重复答案。
猜你喜欢
  • 1970-01-01
  • 2013-11-17
  • 1970-01-01
  • 2018-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-28
  • 1970-01-01
相关资源
最近更新 更多