ListView: Pull-to-refresh

TKListView can be refreshed by a pull-to-refresh gesture. If enabled, the feature allows the user to refresh data by swiping his finger down when the content is scrolled up to the top. This will trigger an animated activity indicator which will stay visible until data is refreshed.

Enabling pull-to-refresh

Use the allowsPullToRefresh property to enable the feature.

listView.allowsPullToRefresh = YES;
listView.allowsPullToRefresh = true
listView.AllowsPullToRefresh = true;

Responding to the pull-to-refresh gesture

To be able to respond to the a pull-to-refresh gesture, you will need to implement the listViewShouldRefreshOnPull: method from the TKListViewDelegateprotocol. After fresh data is available you will need to notify TKListView by calling the didRefreshOnPull method. This call will allow TKListView to hide the activity indicator and display the fresh data.

- (BOOL)listViewShouldRefreshOnPull:(TKListView *)listView
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{

        _newItemsCount = [self updateData:1 + (arc4random() % 3)];

        //waiting a few seconds to simulate data over the wire
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
            //Notifying the ListView that we have fresh data so it can hide the activity indicator and be ready for next load-on demand request.
            [listView didRefreshOnPull];

            if (_newItemsCount < 1) {
                TKAlert *alert = [[TKAlert alloc] initWithTitle:@"Pull to refresh"
                                                        message:@"No more data available!"
                                                       delegate:nil
                                              cancelActionTitle:@"Close"
                                              otherActionTitles:nil];
                [alert show:YES];
            }
        });

    });

    return YES;
}
func listViewShouldRefresh(onPull listView: TKListView) -> Bool {

    DispatchQueue.global(qos: DispatchQoS.QoSClass.userInitiated).async {
        self.newItemsCount = self.updateData(1 + Int(arc4random() % 3))
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(2 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: { () -> Void in
            listView.didRefreshOnPull()

            if(self.newItemsCount < 1){
                let alert = TKAlert()
                alert.title = "Pull to refresh"
                alert.message = "No more data available"
                alert.addAction(TKAlertAction(title: "Close", handler: { (alert:TKAlert, action:TKAlertAction) -> Bool in
                    return true
                }))
                alert.show(true)
            }
        })
    }
    return true
}
public override bool ListViewShouldRefreshOnPull (TKListView listView)
{
    DispatchQueue.DefaultGlobalQueue.DispatchAsync (() => {
        Random r = new Random();
        this.owner.newItemsCount = this.owner.UpdateData(1 + r.Next(0, 4));
        DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 2 * 500000000), () => {
            listView.DidRefreshOnPull();
            if (this.owner.newItemsCount < 1) {
                UIAlertView alert = new UIAlertView("Pull to refresh", "No more data available!",null,"Close",null);
                alert.Show();
            }
        });
    });

    return true;
}