简体   繁体   中英

iOS TableView Long press Gesture going to didselectrowatIndexpath

Guys, I have table view which displays images so for any image tap opens the image in

didselectrowatIndexpath

So I wanted to add a long press gesture so I added

let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressed(_:))) 
cell.baseview.addGestureRecognizer(longPressGesture) 

But each time I press and hold image it is going to didselectrowat method and opening the image instead of going to method longpressed. Is there something I should change for long press gesture action ?

Here is an answer to your question by Apple.

Managing Selections (Responding to Selections)
If the touch occurred in a control embedded in the row, it could respond to the action message sent by the control.

Understanding Responders and the Responder Chain
UIKit directs most events to the most appropriate responder object in your app. If that object does not handle the event, UIKit forwards it to the next responder in the active responder chain, which is a dynamic configuration of your app's responder objects.

Solution:
You have an issue with user interaction of image. Enable user interaction on image view.

cell.baseview.isUserInteractionEnabled = true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM