Unrecognized selector sent to instance Swift 3

前端 未结 1 1819
你的背包
你的背包 2020-12-10 19:49

I want to implement TapGestureRecognizer with the selector, below is the code where I added tapGestureRecognizer to my imageView

相关标签:
1条回答
  • 2020-12-10 20:34

    The problem is with your method declaration and with assigning tag to the object of UIGestureRecognizer. Change your method declaration like this.

    func assignImage(_ sender: UITapGestureRecognizer)
    

    Or

    func assignImage(_ sender: UIGestureRecognizer)
    

    Edit: To access imageView object with UITapGestureRecognizer.

    func assignImage(_ sender: UITapGestureRecognizer) {
        if let imageView = sender.view as? UIImageView {
    
        }
    }
    

    Note: You need to set tag with you imageView not with you UITapGestureRecognizer

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