Search code examples
iphoneiosipaduirefreshcontrol

Need to implement timeout mechanism for UIRefreshControl.


Apple's new UIRefreshControl in iOS 6 is a welcome new feature, but it seems that there is no built-in timeout mechanism.

Here's the scenario why I need it:

Let's say the user pulls the refresh. It goes into the spinning mode, while the code tries to fetch data from the server. The server does not repond and will cause spinning wheel to spin forever. So, there should be a time out mechanism to stop it.

What's the best way to implement it?


Solution

  • First setup a timer with the amount of time you need. Ask it to check the following.

    You can use the following property to check whether it is still refreshing after some time

    @property (nonatomic, readonly, getter=isRefreshing) BOOL refreshing

    If it is then you can stop it using

    endRefreshing

    Something like :

    -(void)checkAndStop{
    if(refreshControl.refreshing == YES) // show an alert if you want
    [refreshControl endRefreshing];
    }