sooper
sooper

Reputation: 6039

Detect touch and hold with UITableViewCell, what are my options?

With my current table view controller, I'd like to implement a touch and hold feature very similar to how the click-wheel iPod's On-The-Go queueing feature used to work.

I've been reading a few posts and have seen suggestions for using UILongPressGestureRecognizer. Whilst I could do that, it does bring up a couple more questions for me:

  1. If a long press is detected, how can I prevent the didSelectRowAtIndexPath method from being called (Or do I completely avoid using it and implement a Tap gesture recogniser in my UITableViewCell subclass?)
  2. How would I go about animating the cell once a long-press has been detected similar to the iPod style (where the highlighted cell flashes/opacity of highlight goes up and down a few times).

Would appreciate some guidance.

Upvotes: 0

Views: 540

Answers (1)

jsd
jsd

Reputation: 7703

If you use the long press recognizer, and it fires, didSelectRowAtIndexPath will not fire.

You can detect the state of the gesture recognizer and animate your cell after the 'start' state is detected, and end the animation when the 'end' state is detected.

if (gestureRecognizer.state == UIGestureRecognizerStateBegan) ... if (gestureRecognizer.state == UIGestureRecognizerStateEnded) ...

Upvotes: 1

Related Questions