【问题标题】:UITableViewCell tap hoverUITableViewCell 点击悬停
【发布时间】:2015-11-16 07:28:34
【问题描述】:

我的 tableviewcell 在选中时具有灰色背景色。但是,我实际上并没有使用 tableview 的“选择”功能,我只是想要悬停效果,因此我在选择后立即取消选择该行,如下所示:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
}

问题是,灰色背景仅在我点击单元格的时间更长时才会显示。如果我快速点击单元格,我看不到灰色背景。

有什么方法可以实现吗?

谢谢。

【问题讨论】:

    标签: ios swift uitableview


    【解决方案1】:

    您可以使用touchesBegantouchesEnded 来执行此操作。 如果触摸在您的表格视图单元格内,您可以添加一点动画。

    请参阅UIResponder Class 了解更多信息:

    https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIResponder_Class/#//apple_ref/occ/instm/UIResponder/touchesBegan:withEvent:

    【讨论】:

      【解决方案2】:

      您可以在 viewDidAppear 上使用它来实现这一点,一旦您重定向到您的视图控制器,此方法将取消选择所选项目。希望这会对您有所帮助:-

      override func viewWillAppear(animated: Bool) {
          tableView.deselectRowAtIndexPath(indexPath, animated: true)
      }
      

      【讨论】:

        猜你喜欢
        • 2016-11-10
        • 2023-03-20
        • 2020-12-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多