Wednesday, August 21, 2013

UIRefreshControl Timeout with Xamarin.iOS

The UIRefreshControl doesn't have a timeout mechanism built into it.  Once the refresh begins, the control will display that a refresh is occurring until the .EndRefreshing() method is called.  Because we are in a mobile environment, the data may never come back.  We don't want to display the UIRefreshControl forever.  Solving this problem is actually pretty simple.  Setup a timer and when the timer runs, call .EndRefreshing().  Here is some code I used for this:
nstRefresh = NSTimer.CreateScheduledTimer( new TimeSpan(0,0,20), delegate{
BeginInvokeOnMainThread(delegate{
if( uir.Refreshing )
{    
       uir.EndRefreshing();
}
});
nstRefresh = null;
});
 
I hope that this helps 

No comments: