PFQueryTableViewController Class Reference
Inherits from | UITableViewController |
---|---|
Conforms to | UITableViewDataSource UITableViewDelegate |
Declared in | PFQueryTableViewController.h |
Overview
This class allows you to think about a one-to-one mapping between a PFObject and a UITableViewCell
,
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 table 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.
Creating a PFQueryTableViewController
– initWithStyle:className:
Initializes with a class name of the PFObject that will be associated with this table.
- (instancetype)initWithStyle:(UITableViewStyle)style className:(nullable NSString *)className
Parameters
style |
The UITableViewStyle for the table |
---|---|
className |
The class name of the instances of PFObject that this table will display. |
Return Value
An initialized PFQueryTableViewController
object or nil
if the object couldn’t be created.
Declared In
PFQueryTableViewController.h
– initWithClassName:
Initializes with a class name of the PFObjects that will be associated with this table.
- (instancetype)initWithClassName:(nullable NSString *)className
Parameters
className |
The class name of the instances of PFObject that this table will display. |
---|
Return Value
An initialized PFQueryTableViewController
object or nil
if the object couldn’t be created.
Declared In
PFQueryTableViewController.h
Configuring Behavior
parseClassName
The class name of the PFObject this table will use as a datasource.
@property (nullable, nonatomic, copy) IBInspectable NSString *parseClassName
Declared In
PFQueryTableViewController.h
textKey
The key to use to display for the cell text label.
@property (nullable, nonatomic, copy) IBInspectable NSString *textKey
Discussion
This won’t apply if you override tableView:cellForRowAtIndexPath:object:
Declared In
PFQueryTableViewController.h
imageKey
The key to use to display for the cell image view.
@property (nullable, nonatomic, copy) IBInspectable NSString *imageKey
Discussion
This won’t apply if you override tableView:cellForRowAtIndexPath:object:
Declared In
PFQueryTableViewController.h
placeholderImage
The image to use as a placeholder for the cell images.
@property (nullable, nonatomic, strong) IBInspectable UIImage *placeholderImage
Discussion
This won’t apply if you override tableView:cellForRowAtIndexPath:object:
Declared In
PFQueryTableViewController.h
loadingViewEnabled
Whether the table should use the default loading view. Default - YES
.
@property (nonatomic, assign) IBInspectable BOOL loadingViewEnabled
Declared In
PFQueryTableViewController.h
pullToRefreshEnabled
Whether the table should use the built-in pull-to-refresh feature. Default - YES
.
@property (nonatomic, assign) IBInspectable BOOL pullToRefreshEnabled
Declared In
PFQueryTableViewController.h
paginationEnabled
Whether the table should use the built-in pagination feature. Default - YES
.
@property (nonatomic, assign) IBInspectable BOOL paginationEnabled
Declared In
PFQueryTableViewController.h
objectsPerPage
The number of objects to show per page. Default - 25
.
@property (nonatomic, assign) IBInspectable NSUInteger objectsPerPage
Declared In
PFQueryTableViewController.h
loading
Whether the table is actively loading new data from the server.
@property (nonatomic, assign, getter=isLoading) BOOL loading
Declared In
PFQueryTableViewController.h
Responding to Events
– objectsWillLoad
Called when objects will loaded from Parse. If you override this method, you must call [super objectsWillLoad] in your implementation.
- (void)objectsWillLoad
Discussion
Called when objects will loaded from Parse. If you override this method, you must call [super objectsWillLoad] in your implementation.
Declared In
PFQueryTableViewController.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
PFQueryTableViewController.h
Accessing Results
objects
The array of instances of PFObject that is used as a data source.
@property (nullable, nonatomic, copy, readonly) NSArray *objects
Declared In
PFQueryTableViewController.h
– objectAtIndexPath:
Returns an object at a particular indexPath.
- (nullable PFObject *)objectAtIndexPath:(nullable NSIndexPath *)indexPath
Parameters
indexPath |
The indexPath. |
---|
Return Value
The object at the specified index
Discussion
The default impementation returns the object at indexPath.row
.
If you want to return objects in a different indexPath order, like for sections, override this method.
Declared In
PFQueryTableViewController.h
– removeObjectAtIndexPath:
Removes an object at the specified index path, animated.
- (void)removeObjectAtIndexPath:(nullable NSIndexPath *)indexPath
Declared In
PFQueryTableViewController.h
– removeObjectAtIndexPath:animated:
Removes an object at the specified index path, with or without animation.
- (void)removeObjectAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated
Declared In
PFQueryTableViewController.h
– removeObjectsAtIndexPaths:
Removes all objects at the specified index paths, animated.
- (void)removeObjectsAtIndexPaths:(nullable NSArray *)indexes
Declared In
PFQueryTableViewController.h
– removeObjectsAtIndexPaths:animated:
Removes all objects at the specified index paths, with or without animation.
- (void)removeObjectsAtIndexPaths:(nullable NSArray *)indexes animated:(BOOL)animated
Declared In
PFQueryTableViewController.h
– loadObjects
Clears the table and loads the first page of objects.
- (BFTask *)loadObjects
Return Value
An awaitable task that completes when the reload succeeds
Declared In
PFQueryTableViewController.h
– loadObjects:clear:
Loads the objects of the className at the specified page and appends it to the objects already loaded and refreshes the table.
- (BFTask *)loadObjects:(NSInteger)page clear:(BOOL)clear
Parameters
page |
The page of objects to load. |
---|---|
clear |
Whether to clear the table after receiving the objects |
Return Value
An awaitable task that completes when the reload succeeds
Declared In
PFQueryTableViewController.h
– loadNextPage
Loads the next page of objects, appends to table, and refreshes.
- (void)loadNextPage
Declared In
PFQueryTableViewController.h
Querying
– queryForTable
Override to construct your own custom PFQuery to get the objects.
- (PFQuery *)queryForTable
Return Value
PFQuery that loadObjects will use to the objects for this table.
Discussion
Override to construct your own custom PFQuery to get the objects.
Declared In
PFQueryTableViewController.h
Data Source Methods
– tableView:cellForRowAtIndexPath:object:
Override this method to customize each cell given a PFObject that is loaded.
- (nullable PFTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(nullable PFObject *)object
Parameters
tableView |
The table 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
If you don’t override this method, it will use a default style cell and display either
the first data key from the object, or it will display the key as specified with textKey
, imageKey
.
Warning: The cell should inherit from PFTableViewCell which is a subclass of UITableViewCell
.
Declared In
PFQueryTableViewController.h
– tableView:cellForNextPageAtIndexPath:
Override this method to customize the cell that allows the user to load the next page when pagination is turned on.
- (nullable PFTableViewCell *)tableView:(UITableView *)tableView cellForNextPageAtIndexPath:(NSIndexPath *)indexPath
Parameters
tableView |
The table view object associated with this controller. |
---|---|
indexPath |
The indexPath of the cell. |
Return Value
The cell that allows the user to paginate.
Discussion
Override this method to customize the cell that allows the user to load the next page when pagination is turned on.
Declared In
PFQueryTableViewController.h