can't click UIButton inside a cell in UITableview

前端 未结 13 1824
生来不讨喜
生来不讨喜 2021-02-05 09:51

searched already some possible fixes but all did not solve mine.

i keep clicking the cell in the uitableview rather than the buttons inside it.

here is my code:

相关标签:
13条回答
  • 2021-02-05 10:41

    I was doing this:

    let plusButton: UIButton = {
            let v = UIButton()
            v.setImage(plusImg, for: .normal)
            v.tintColor = .dark
            v.translatesAutoresizingMaskIntoConstraints = false
            v.addTarget(self, action: #selector(plusButtonHandler), for: .touchUpInside)
            // adding targets here did not work
            return v
        }()
    

    And it appears invoking the addTarget method inside of the closure did not work. When I factored the addTarget method out and instead put it in the initializer, everything worked!

    0 讨论(0)
提交回复
热议问题