So I have a custom cell class and a xib file for my cells in my tableview, and I want to add a long press recognition to the custom cell.
I tried to drag and drop the long press recognizer to the cell in the xib-file, make the file's owner the gesture's delegate, and then "drag and add" it from the document outline to the custom class swift-file. I also added the UIGestureRecognizerDelegate to the custom cell class.
Now when I run the app I get a Thread 1: signal SIGABRT error, and honestly I have no idea why. This is the first time I use the gesture recognizer so sorry if there's an obvious mistake or something I should've done.
Any suggestions on how to proceed would be appreciated.
EDIT: As Logan suggested I undid everything that was done and followed his steps. The code in my custom class now looks like this:
@IBAction func pressed(sender: AnyObject) {
func handleLongPress(sender: UILongPressGestureRecognizer) {
if sender.state == .Began {
println("Received longPress!")
}
}
}
But I still get the error. What I noticed is that if I just add the gesture to the xib-file and run the app, I get the error. I don't know if that is because I haven't connected it to the custom class file yet, but I thought I'd just throw it out there.
EDIT 2: After changing my code to this:
@IBAction func pressed(sender: UILongPressGestureRecognizer) {
if sender.state == .Began {
println("Received longPress!")
}
}
I still get the error.
I don't know if I made this clear, but I can't even load the screen, it just crashes right away. So I'm thinking this is a delegation/reference issue, here's how my references are:
1) I set the class of my xib-file owner to the custom cell class. 2) I dragged the gesture recognizer on the cell. 3) I dragged the gesture object to the file-owner so that the file owner is its delegate. 4) I added the code from above in my custom class. 5) I dragged the gesture object to the file-owner so that the gesture is "connected to the code" in the custom class.
These are all my steps, and as I said, I suspect there's a delegate issue somewhere.