0

我有一个UITableView设置,我正在探索突出显示的所有不同选项,UITableViewCell我想知道以下几点:

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        .
        .
    cell.selectionStyle = .gray
    return cell
}

What happens now is that when a cell is selected it is highlighted with a grey color, I was wondering, is it possible to deselect the cell after about 0.5 sec?

基本上是否可以使单元格仅短暂闪烁,以便用户知道他与单元格交互,但它不会保持选中状态?我将此 tableView 用于侧面菜单,并且保持突出显示不是我想要的行为。

谢谢!

4

2 回答 2

3

您可以取消选择didSelectRow方法上的行,单元格将突出显示,然后选择将淡出,让用户知道他们与单元格进行了交互。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  tableView.deselectRow(at: indexPath, animated: true)
  // Do whatever else you need
}
于 2018-10-30T18:19:40.310 回答
0

终于让它工作了,我所做的是:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
 tableView.cellForRow(at: indexPath)?.backgroundColor = .gray
    DispatchQueue.main.asyncAfter(deadline: .now()) {
        UIView.animate(withDuration: 0.5, animations: {
            tableView.cellForRow(at: indexPath)?.backgroundColor = .none
        })
    }

也许这会帮助别人。唯一的问题是,被点击的单元格在按下时不会突出显示,只有在手势结束后(即仅被点击)。如果有人对此有解决方案,我将不胜感激,但现在就可以了。

于 2018-10-30T18:12:23.230 回答