Xamarin.iOS Adding UIRefreshControl to a table view Addind a simple UIRefreshControl to a UIScrollView

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

We assume a fully working UIScrollview named _scrollView;

Note that UITableView, UICollectionView are also scrollviews, hence the following examples would work on those UI elements.

First, creation & allocation

UIRefreshControl refreshControl = new UIRefreshControl();

Second, connecting the refresh event to a method. There are different ways to do that.

Style 1:

refreshControl.ValueChanged += (object sender, EventArgs e) => MyMethodCall();

Style 2:

refreshControl.ValueChanged += (object sender, EventArgs e) =>
{
    //Write code here
};

Style 3:

refreshControl.ValueChanged += HandleRefreshValueChanged;

void HandleRefreshValueChanged(object sender, EventArgs e)
{
    //Write code here
}

Third and last, adding the refresh control itself to our scrollview.

_scrollView.AddSubview(refreshControl);


Got any Xamarin.iOS Question?