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?
CollectionView is an object that presents the ordered collection of data items in the customizable layouts. It shows the data in the form of a grid layout. A collectionview is an instance of the UICollectionView class, which inherits the UIScrollView, which will be covered later in this tutorial.
A collection view manages an ordered set of content, such as the grid of photos in the Photos app, and presents it visually. Collection views are a collaboration between many different objects, including: Cells. A cell provides the visual representation for each piece of your content.
UILongPressGestureRecognizer is a concrete subclass of UIGestureRecognizer . The user must press one or more fingers on a view and hold them there for a minimum period of time before the action triggers.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With