How to add gesture to UITableViewCell?

前端 未结 4 790
有刺的猬
有刺的猬 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:22

    Adding gesture in awakeFromNib method seems much more easier and works fine.

    class TestCell: UITableViewCell {
    
        override func awakeFromNib() {
            super.awakeFromNib()
    
            let panGesture = UIPanGestureRecognizer(target: self,
                                                action: #selector(gestureAction))
            addGestureRecognizer(panGesture)
        }
    
        @objc func gestureAction() {
            print("gesture action")
        }
    }
    

提交回复
热议问题