【问题标题】:selectionStyle in iPhone UITableViewCell selectionStyle when editing? [duplicate]编辑时 iPhone UITableViewCell selectionStyle 中的 selectionStyle? [复制]
【发布时间】:2012-12-25 03:04:27
【问题描述】:

可能重复:
How can I disable the UITableView selection highlighting?

当您点击UITableView 中的一行时,该行将突出显示并被选中。是否可以禁用此功能,因此点击一行什么也不做?

【问题讨论】:

  • 在 dup 文章中,我更喜欢在 tableView 的属性上设置 allowSelection=NO 的投票率较低的答案。
  • allowsSelection 设置为NO 很好,但前提是您希望整个表视图具有不可选择的行。要对单个单元格的可选择性进行更细粒度的控制,请改用UITableViewCellselectionStyle 属性。

标签: iphone ios objective-c xcode


【解决方案1】:

是的,下面的代码将禁用用户交互,如果你只是想禁用某些单元格,你需要编写一些 if-else 方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell.userInteractionEnabled = NO;

    return cell;
}

【讨论】:

  • 这样会阻止单元格接收触摸事件,这可能不是他想要的。
  • 好吧,如果你禁用用户交互,用户就不能点击它:),而且他可能使用了一个假帐户
【解决方案2】:

如果您的单元格上有按钮或任何仍需要“可触摸”的东西,则只需将选择样式设置为无:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

如果它只是一个带有文本的单元格,那么你可以像 Space Dust 建议的那样做。

【讨论】:

    【解决方案3】:

    此问题已回复before

    获取UITableViewCell 实例并设置以下属性:

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    

    【讨论】:

      【解决方案4】:

      你也可以试试这个:

      -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
      {
          [tableView deselectRowAtIndexPath:indexPath animated:YES];
      
          //do ur stuff
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-09-18
        • 1970-01-01
        • 1970-01-01
        • 2018-09-15
        • 1970-01-01
        • 1970-01-01
        • 2011-08-12
        相关资源
        最近更新 更多