PFQueryCollectionViewController Class Reference
Inherits from | UICollectionViewController |
---|---|
Conforms to | UICollectionViewDelegateFlowLayout |
Declared in | PFQueryCollectionViewController.h |
Overview
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.
Other Methods
parseClassName
The class name of the PFObject this collection will use as a datasource.
@property (nullable, nonatomic, copy) IBInspectable NSString *parseClassName
Declared In
PFQueryCollectionViewController.h
loadingViewEnabled
Whether the collection should use the default loading view. Default - YES
.
@property (nonatomic, assign) IBInspectable BOOL loadingViewEnabled
Declared In
PFQueryCollectionViewController.h
pullToRefreshEnabled
Whether the collection should use the built-in pull-to-refresh feature. Default - YES
.
@property (nonatomic, assign) IBInspectable BOOL pullToRefreshEnabled
Declared In
PFQueryCollectionViewController.h
paginationEnabled
Whether the collection should use the built-in pagination feature. Default - YES
.
@property (nonatomic, assign) IBInspectable BOOL paginationEnabled
Declared In
PFQueryCollectionViewController.h
objectsPerPage
The number of objects to show per page. Default - 25
.
@property (nonatomic, assign) IBInspectable NSUInteger objectsPerPage
Declared In
PFQueryCollectionViewController.h
loading
Whether the collection is actively loading new data from the server.
@property (nonatomic, assign, getter=isLoading) BOOL loading
Declared In
PFQueryCollectionViewController.h
Creating a PFQueryCollectionViewController
– initWithClassName:
Initializes a view controller with a UICollectionViewFlowLayout
and a class name
of PFObject that will be associated with this collection.
- (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.
Declared In
PFQueryCollectionViewController.h
– initWithCollectionViewLayout:className:
Initializes a view controller with a class name of PFObject that will be associated with this collection.
- (instancetype)initWithCollectionViewLayout:(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.
Declared In
PFQueryCollectionViewController.h
Responding to Events
– objectsWillLoad
Called when objects will be loaded from Parse. If you override this method, you must call [super objectsWillLoad] in your implementation.
- (void)objectsWillLoad
Discussion
Called when objects will be loaded from Parse. If you override this method, you must call [super objectsWillLoad] in your implementation.
Declared In
PFQueryCollectionViewController.h
– objectsDidLoad:
Called when objects have loaded from Parse. If you override this method, you must call [super objectsDidLoad:] in your implementation.
- (void)objectsDidLoad:(nullable NSError *)error
Parameters
error |
The Parse error from running the PFQuery, if there was any. |
---|
Discussion
Called when objects have loaded from Parse. If you override this method, you must call [super objectsDidLoad:] in your implementation.
Declared In
PFQueryCollectionViewController.h
Accessing Results
objects
The array of instances of PFObject that is used as a data source.
@property (nonatomic, copy, readonly) NSArray *objects
Declared In
PFQueryCollectionViewController.h
– objectAtIndexPath:
Returns an object at a particular indexPath.
- (nullable PFObject *)objectAtIndexPath:(nullable NSIndexPath *)indexPath
Parameters
indexPath |
An instance of |
---|
Return Value
The object at the specified indexPath.
Discussion
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.
Declared In
PFQueryCollectionViewController.h
– removeObjectAtIndexPath:
Removes an object at the specified index path, animated.
- (void)removeObjectAtIndexPath:(nullable NSIndexPath *)indexPath
Declared In
PFQueryCollectionViewController.h
– removeObjectsAtIndexPaths:
Removes all objects at the specified index paths, animated.
- (void)removeObjectsAtIndexPaths:(nullable NSArray *)indexes
Declared In
PFQueryCollectionViewController.h
Loading Data
– loadObjects
Clears the collection view and loads the first page of objects.
- (BFTask *)loadObjects
Return Value
An awaitable task that completes when the reload succeeds
Declared In
PFQueryCollectionViewController.h
– loadObjects:clear:
Loads the objects of the parseClassName at the specified page and appends it to the objects already loaded and refreshes the collection.
- (BFTask *)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
Declared In
PFQueryCollectionViewController.h
– loadNextPage
Loads the next page of objects, appends to table, and refreshes.
- (void)loadNextPage
Declared In
PFQueryCollectionViewController.h
– clear
Clears the collection view of all objects.
- (void)clear
Declared In
PFQueryCollectionViewController.h
Querying
– queryForCollection
Override to construct your own custom PFQuery to get the objects.
- (PFQuery *)queryForCollection
Return Value
An instance of PFQuery that loadObjects method will use to the objects for this collection.
Declared In
PFQueryCollectionViewController.h
Data Source Methods
– collectionView:cellForItemAtIndexPath:object:
Override this method to customize each cell given a PFObject that is loaded.
- (nullable PFCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(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.
Discussion
Warning: The cell should inherit from PFCollectionViewCell which is a subclass of UICollectionViewCell
.
Declared In
PFQueryCollectionViewController.h
– collectionViewReusableViewForNextPageAction:
Override this method to customize the view that allows the user to load the next page when pagination is turned on.
- (nullable UICollectionReusableView *)collectionViewReusableViewForNextPageAction:(UICollectionView *)collectionView
Parameters
collectionView |
The collection view object associated with this controller. |
---|
Return Value
The view that allows the user to paginate.
Discussion
Override this method to customize the view that allows the user to load the next page when pagination is turned on.
Declared In
PFQueryCollectionViewController.h