PFQueryCollectionViewController

@interface PFQueryCollectionViewController
    : UICollectionViewController <UICollectionViewDelegateFlowLayout>

This class allows you to think about a one-to-one mapping between a PFObject and a UICollectionViewCell, rather than having to juggle index paths.

You also get the following features out of the box:

  • Pagination with a cell that can be tapped to load the next page.
  • Pull-to-refresh collection view header.
  • Automatic downloading and displaying of remote images in cells.
  • Loading screen, shown before any data is loaded.
  • Automatic loading and management of the objects array.
  • Various methods that can be overridden to customize behavior at major events in the data cycle.

    • The class name of the PFObject this collection will use as a datasource.

      Declaration

      Objective-C

      @property (readwrite, copy, nonatomic, nullable) NSString *parseClassName;
    • Whether the collection should use the default loading view. Default - YES.

      Declaration

      Objective-C

      @property (assign, readwrite, nonatomic) BOOL loadingViewEnabled;
    • Whether the collection should use the built-in pull-to-refresh feature. Default - YES.

      Declaration

      Objective-C

      @property (assign, readwrite, nonatomic) BOOL pullToRefreshEnabled;
    • Whether the collection should use the built-in pagination feature. Default - YES.

      Declaration

      Objective-C

      @property (assign, readwrite, nonatomic) BOOL paginationEnabled;
    • The number of objects to show per page. Default - 25.

      Declaration

      Objective-C

      @property (assign, readwrite, nonatomic) NSUInteger objectsPerPage;
    • Whether the collection is actively loading new data from the server.

      Declaration

      Objective-C

      @property (getter=isLoading, assign, readwrite, nonatomic) BOOL loading;
    • Initializes a view controller with a UICollectionViewFlowLayout and a class name of PFObject that will be associated with this collection.

      Declaration

      Objective-C

      - (nonnull instancetype)initWithClassName:(nullable NSString *)className;

      Parameters

      className

      The class name of the instances of PFObject that this table will display.

      Return Value

      An initialized PFQueryCollectionViewController object or nil if the object couldn’t be created.

    • Initializes a view controller with a class name of PFObject that will be associated with this collection.

      Declaration

      Objective-C

      - (nonnull instancetype)
          initWithCollectionViewLayout:(nonnull UICollectionViewLayout *)layout
                             className:(nullable NSString *)className;

      Parameters

      layout

      Layout for collection view to use.

      className

      The class name of the instances of PFObject that this table will display.

      Return Value

      An initialized PFQueryCollectionViewController object or nil if the object couldn’t be created.

    • Called when objects will be loaded from Parse. If you override this method, you must call [super objectsWillLoad] in your implementation.

      Declaration

      Objective-C

      - (void)objectsWillLoad;
    • Called when objects have loaded from Parse. If you override this method, you must call [super objectsDidLoad:] in your implementation. - parameter: error The Parse error from running the PFQuery, if there was any.

      Declaration

      Objective-C

      - (void)objectsDidLoad:(nullable NSError *)error;

      Parameters

      error

      The Parse error from running the PFQuery, if there was any.

    • The array of instances of PFObject that is used as a data source.

      Declaration

      Objective-C

      @property (readonly, copy, nonatomic)
          NSArray<__kindof PFObject *> *_Nonnull objects;
    • Returns an object at a particular indexPath.

      The default impementation returns the object at indexPath.item. If you want to return objects in a different indexPath order, like for sections, override this method.

      Declaration

      Objective-C

      - (nullable PFObject *)objectAtIndexPath:(nullable NSIndexPath *)indexPath;

      Parameters

      indexPath

      An instance of NSIndexPath.

      Return Value

      The object at the specified indexPath.

    • Removes an object at the specified index path, animated.

      Declaration

      Objective-C

      - (void)removeObjectAtIndexPath:(nullable NSIndexPath *)indexPath;
    • Removes all objects at the specified index paths, animated.

      Declaration

      Objective-C

      - (void)removeObjectsAtIndexPaths:(nullable NSArray<NSIndexPath *> *)indexes;
    • Clears the collection view and loads the first page of objects.

      Declaration

      Objective-C

      - (nonnull BFTask<NSArray<__kindof PFObject *> *> *)loadObjects;

      Return Value

      An awaitable task that completes when the reload succeeds

    • Loads the objects of the PFObject.parseClassName at the specified page and appends it to the objects already loaded and refreshes the collection.

      Declaration

      Objective-C

      - (nonnull BFTask<NSArray<__kindof PFObject *> *> *)loadObjects:(NSInteger)page
                                                                clear:(BOOL)clear;

      Parameters

      page

      The page of objects to load.

      clear

      Whether to clear the collection view after receiving the objects.

      Return Value

      An awaitable task that completes when the reload succeeds

    • Loads the next page of objects, appends to table, and refreshes.

      Declaration

      Objective-C

      - (void)loadNextPage;
    • Clears the collection view of all objects.

      Declaration

      Objective-C

      - (void)clear;
    • Override to construct your own custom PFQuery to get the objects.

      Declaration

      Objective-C

      - (nonnull PFQuery *)queryForCollection;

      Return Value

      An instance of PFQuery that -loadObjects method will use to the objects for this collection.

    • Override this method to customize each cell given a PFObject that is loaded.

      Warning

      The cell should inherit from PFCollectionViewCell which is a subclass of UICollectionViewCell.

      Declaration

      Objective-C

      - (nullable PFCollectionViewCell *)
                  collectionView:(nonnull UICollectionView *)collectionView
          cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath
                          object:(nullable PFObject *)object;

      Parameters

      collectionView

      The collection view object associated with this controller.

      indexPath

      The indexPath of the cell.

      object

      The PFObject that is associated with the cell.

      Return Value

      The cell that represents this object.

    • Override this method to customize the view that allows the user to load the next page when pagination is turned on.

      Declaration

      Objective-C

      - (nullable UICollectionReusableView *)
          collectionViewReusableViewForNextPageAction:
              (nonnull UICollectionView *)collectionView;

      Parameters

      collectionView

      The collection view object associated with this controller.

      Return Value

      The view that allows the user to paginate.