Working on Pull to Refresh

Dheeraj Kumar Gunti

Reading Time : ( words)


Updating data on demand is the concept of Pull to refresh. Extending the basic process of Pull to refresh we can customize it to our needs. Here is the small sample of how to work with pull to refresh with DialogController.

UIRefreshControl is the basic control which is used to initiate refresh to the tableview.

public class DemoRefreshController : DialogViewController
{
    RootElement root = new RootElement ("Pull To Refresh") {
    new Section ("Items") {
    }
    };
    int i = 0;
    public DemoRefreshController () : base (UITableViewStyle.Grouped, null)
    {
    this.NavigationItem.HidesBackButton = false;
        root.Add (new Section ());
    this.Root = root;
    var refreshControl = new UIRefreshControl ();
        refreshControl.AttributedTitle = new NSAttributedString ("Refreshing...");
        refreshControl.AddTarget (this, new Selector ("refresh:"), UIControlEvent.AllEvents);
    this.RefreshControl = refreshControl;
    }
    [Export ("refresh:")]
    public void refresh (NSObject sender)
    {
        NSTimer.CreateScheduledTimer (1, delegate {
            root [0].Add (new StringElement ("Added " + (++i)));
    this.ReloadComplete ();
    var control = (UIRefreshControl)sender;
            control.EndRefreshing ();
    });
    }
}