代码之家  ›  专栏  ›  技术社区  ›  Ariel Malka

如何在iPhoneOS3.0之前的uiTableView上模拟allowselection?

  •  0
  • Ariel Malka  · 技术社区  · 15 年前

    在OS3.0上,当allowsselection=no时,不可能选择任何行,也会取消行突出显示。

    在OS 3.0之前的版本中,最明显的不允许选择的解决方案是在willSelectRowatindexpath中返回nil,willSelectRowatindexpath是uiTableViewDelegate的一部分。

    但是,这种方法有两个问题:

    1)它不稳定(即经常选择一行…)
    2)不取消行突出显示

    有什么线索吗?

    2 回复  |  直到 15 年前
        1
  •  4
  •   Ed Marty    15 年前

    你应该设置 selectionStyle 关于个人 UITableViewCell 你不想被选中 UITableViewCellSelectionStyleNone . 对于那些你想选择的人, UITableViewCellSelectionStyleBlue . 基本上:

    - (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        //...
        cell.selectionStyle = (canSelectRow ? UITableViewCellSelectionStyleBlue : UITableViewCellSelectionStyleNone);
        return cell;
    }
    
        2
  •  1
  •   Vladimir    15 年前

    要取消行突出显示,可以将单元格的SelectionStyle设置为UITableViewCellSelectionStyleNone。

    从willselectrowatindexpath返回nil始终对我有效…