I want to add a longPressGestureRecocnizer
to a collection view cell and pass in the indexPath of the cell to work with it. I tried to do this by adding this to the cellForItemAt
method:
let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressGetstureFunction(indexPath:)))
cell.addGestureRecognizer(longPressGesture)
This is the method I call with the #Selector:
@objc func longPressGetstureFunction(indexPath: Int) {
print("long press gesture detected")
Alert.showColectionViewDataAlert(on: self, indexRow: indexPath)
}
But when I pass in a integer for the indexPath like this:
let longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressGetstureFunction(indexPath: 5)))
I get the following error message from Xcode:
Argument of '#selector' does not refer to an '@objc' method, property, or initializer
I google a lot on this topic, and I saw also a few answers to the same kind of question on StackOverflow, but all the answer either have objective-C code, or code that is not relevant to colectionView's.
Does anyone have an idea of how I would do this?
Thanks! Benji