I would like to handle a long press on a UITableViewCell
to print a "quick access menu".
Did someone already do this?
Particularly the gesture recognize on UITableView
?
I would like to handle a long press on a UITableViewCell
to print a "quick access menu".
Did someone already do this?
Particularly the gesture recognize on UITableView
?
I put together a little category on UITableView based on Anna Karenina's excellent answer.
Like this you'll have a convenient delegate method like you're used to when dealing with regular table views. Check it out:
If you want to use this in a UITableViewController, you probably need to subclass and conform to the new protocol.
It works great for me, hope it helps others!
Just add UILongPressGestureRecognizer to the given prototype cell in storyboard, then pull the gesture to the viewController's .m file to create an action method. I made it as I said.
Looks to be more efficient to add the recognizer directly to the cell as shown here:
Tap&Hold for TableView Cells, Then and Now
(scroll to the example at the bottom)
Use the UITouch timestamp property in touchesBegan to launch a timer or stop it when touchesEnded got fired
First add the long press gesture recognizer to the table view:
Then in the gesture handler:
You have to be careful with this so that it doesn't interfere with the user's normal tapping of the cell and also note that
handleLongPress
may fire multiple times (this will be due to the gesture recognizer state changes).Answer in Swift:
Add delegate
UIGestureRecognizerDelegate
to your UITableViewController.Within UITableViewController:
And the function: