【问题标题】:Cells not getting selected in UITableView with allowsMultipleSelectionDuringEditing set in edit mode在编辑模式下设置了allowMultipleSelectionDuringEditing 的UITableView 中未选择单元格
【发布时间】:2014-06-05 16:31:32
【问题描述】:

我有一个UITableView,它被配置为允许在编辑模式下选择多个单元格。但是,在触摸/选择单元格后,左侧的空白色圆圈永远不会变为带有白色复选标记的红色圆圈。

我已经阅读了allowsMultipleSelectionDuringEditing 的滑动删除问题,所以我的setEditing:animinated 方法如下所示:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    self.tableView.allowsMultipleSelectionDuringEditing = editing;
    [super setEditing:editing animated:animated];
}

网上有些资源建议设置allowsSelectionDuringEditing = NO;,但是没有效果。另外,我的单元格编辑样式设置为UITableViewCellEditingStyleDelete,更改它也没有任何效果。

在编辑模式下触摸一行时,会触发tableView:didSelectRowForIndexpath:,但如上所述,UI 并没有反映这一点。

【问题讨论】:

    标签: ios uitableview multiple-select


    【解决方案1】:

    通常情况下,这是我的错误。

    问题出在我对tableView:cellForRowAtIndexPath: 的实现中,我将单元格的selectionStyle 属性设置为UITableViewCellSelectionStyleNone。出于某种原因,这增加了在多选编辑模式下禁用左侧红色复选标记的“好处”。

    设置cell.selectionStyle = UITableViewCellSelectionStyleGray; 解决了这个问题。

    【讨论】:

    • 感谢 2018 年。终于找到了这个答案并解决了我的问题!
    【解决方案2】:

    旧线程,但我也遇到了这个问题,但是我发现我的自定义单元格的原因是在没有调用 super 的情况下覆盖了 setSelected 和 setHighlighted 方法。

    这导致单元格无法选择。

    【讨论】:

    • 感谢 2020 年。我遇到了类似的问题:我的自定义 UITableViewCell 没有调用 [super setEditing:animated]。
    【解决方案3】:

    我遇到了类似的问题,因为我非常努力地确保我的单元格永远不会显示任何选择(对于“聊天气泡”样式的表格)。

    因此,这个修复当然会在我的桌子上产生很大的大彩条,我必须找到另一种方法来消除它们。

    在你的 cellForRowAtIndexPath 中,你可以设置一个 selectedBackgroundView 而不是设置 selectionStyle,它也会启用复选框。视图可以是单元格的背景颜色或 clearColor,然后什么都不会显示。这是我的代码:

    static dispatch_once_t onceToken;
    static UIView * selectedBackgroundView;
    dispatch_once(&onceToken, ^{
        selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
        selectedBackgroundView.backgroundColor = APP_CELL_BACKGROUND_COLOR;
    });
    cell.selectedBackgroundView = selectedBackgroundView;
    

    【讨论】:

      【解决方案4】:

      我遇到了同样的问题。确保tableView:shouldHighlightRowAtIndexPath: 返回YES,否则将不会发生选择,至少在iOS 7 中是这样。

      - (BOOL)tableView:(UITableView *)tableView
          shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
      {
          return YES;
      }
      

      【讨论】:

        猜你喜欢
        • 2011-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-02
        • 1970-01-01
        • 2010-12-21
        • 1970-01-01
        • 2016-03-02
        相关资源
        最近更新 更多