Search code examples
xcodeparse-platformtableviewpull-to-refresh

How to Add Pull-To-Refresh to a Tableview "Query from Parse.com"


I have an app that query data from a class in Parse.com.

I'm able to populate the table correctly.

How can i add a Pull to Refresh to refresh the tableview ?

Thanks!

enter image description here


Solution

    1. Add the refresh control, making your datasource-providing class the target.
    2. When the refresh action triggers, invoke the parse query code you already have working to fetch from parse. That query must already reloadData when it is done.
    3. Add a line to that completion block to tell your refresh control to endRefreshing.

    EDIT - most of the time, the view controller containing the table is also the table's datasource. If that's the case, then create the refresh control in that same view controller's viewDidLoad method.

    UIRefreshControl  *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self
                       action:@selector(refresh:)
             forControlEvents:UIControlEventValueChanged];
    

    Set the target to self and in that same class implement the selector refresh, which will have a signature like this:

    - (void)refresh:(UIRefreshControl *)control {
        // step two:  from here, invoke the same parse query code you have working
    }