How to add gesture to UITableViewCell?

前端 未结 4 785
有刺的猬
有刺的猬 2021-02-05 14:56

I want to add a tap gesture to every cell in a UITableView that edits the content in it. The two ways to add a gesture are in code or through storyboard. I tried bo

4条回答
  •  伪装坚强ぢ
    2021-02-05 15:15

    You don't need to add gesture recognizer to achieve what you are doing.

    • Use the UITableViewDelegate method tableView:didSelectRowAtIndexPath: to detect which row is tapped (this is what exactly your tapGesture is going to do) and then do your desired processing.
    • If you don't like the gray indication when you select cell, type this in your tableView:didEndDisplayingCell:forRowAtIndexPath: just before returning the cell:
      cell?.selectionStyle = .None

提交回复
热议问题