Reputation: 5776
I'm currently working on a project for an iPad app. The main screen is a UICollectionView
with AlbumCell
's, a subclass of UICollectionViewCell
. Now I wanted to add an UILongPressGestureRecognizer
to pop up an UIActionSheet
.
First I tried that in the UICollectionViewController
, but I figured that that isn't the right place to add those. So my best guess is adding the gesture in the AlbumCell
class? Then probably adding itself as delegate, so it catches it's own gestures.
Is this a good approach so far?
After I catch the gesture, I should show the UIActionSheet
. Now I open it in the UICollectionViewController
when the user selects a cell while in editing mode. But should I call a method on the UICollectionViewController
to open it, like I do now? Or should the cell handle it's own UIActionSheet
?
Eventually I got to let the UICollectionViewController
what to do, might be to let him open the UIActionSheet
, or handle accordingly to the result of it. How should the AlbumCell
"communicate" with it?
It's something I've been struggling with multiple times, not just in this use case. Is the approach close, or should I handle those actions totally different?
Upvotes: 7
Views: 3558
Reputation: 12421
You can adopt the same method of using UILongPressGestureRecognizer
on UITableView
.
Basically, set up one recognizer. In the selector, use the indexPathForItemAtPoint:
to find out what index path the user was pressing on. Finally, if the user is pressing on a cell (and not pressing on the space in between cells), present the UIActionSheet
however you like.
Upvotes: 13