代码之家  ›  专栏  ›  技术社区  ›  Rob

调用deselectrowatindexpath后,accessorydetaildisclosurebutton未取消选择

  •  2
  • Rob  · 技术社区  · 16 年前

    在我的TableView中,我有许多行具有“披露详细信息”按钮“附件类型”,当按下该行或附件时,将向导航控制器推送一个新视图。我在didselectrowatindexpath函数的末尾调用deselectrowatindexpath。

    如果我按下附件按钮,我会转到一个新视图,但当我回到这个视图(弹出)时,它会保持突出显示。行按预期取消选择,但不是这样。有没有想过如何“解开”它?

    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        ...
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
        }
        - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
         [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
         [self tableView:tableView didSelectRowAtIndexPath:indexPath];
        }
    
    2 回复  |  直到 15 年前
        1
  •  1
  •   Massimo Cafaro    16 年前

    只需从您的

    - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
    

    方法陈述

    [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
    

    因为您的表已经允许选择,并且您在

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
    

    您完成了,因为当选择该行时,按下“披露”按钮将突出显示该行,当 tableView:didSelectRowAtIndexPath: 执行。

        2
  •  3
  •   ynnckcmprnl    15 年前

    对于那些仍然对此感到困扰并希望立即找到有效解决方案的人,请尝试以下方法:

    - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
    
    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
    [tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
    
    }
    

    必须先重新加载数据,然后选择行,以便突出显示显示在操作表选项下面。