While the title might be evocative of a cheap adult film, the pull-down to refresh mechanism is now the de-facto control to retrieve new data from a server. All social apps including the official Twitter and Facebook for iOS implement this functionality currently. So how would you implement this rather neat feature? Constructing your own custom Pull Down to Refresh mechanism might be a little painful and time-consuming but luckily there are two well-coded open source frameworks that you can easily use to integrate this feature into your project.

The first of the two frameworks is by Leah Culver. You can find the source here. I personally preferred using the framework provided by Enermego as it is easy to integrate and looks better than any other open-source available out there. The source code can be found here. I will give you a brief introduction on how you can use this framework in your own project.

Download the source code and copy the folder titled ‘EGOTableViewPullRefresh’ into your Xcode project. The folder essentially consists of a .h and a .m file along with few images to indicate data loading.

Now to get your hands dirty with the implementation.
First create an instance of the Class that you have just imported into your project along with a BOOL variable to indicate whether the table is still reloading. Also, mention the delegate that you will be using. Here’s how it will look:

Now in your viewDidLoad method of your .m file, initialize your myTableView and add it as a subView of your main view. Alternately you can create your tableView in Interface Builder as i chose to do.
Add the following code snippet to your viewDidLoad method:

The above lines of code essentially create the ‘refresh-enabled’ table with the same dimensions of myTableView and assigns self as the delegate. We also call the method that refreshes the last updated date. Now we add the delegate methods of the EGORefreshTableHeaderView and the UIScrollView classes.

That’s all there is to it. You can tinker with your delay values depending on your project. But this nifty little framework will give you a readymade Pull Down to Reload feature that you can have up and running in no time. Do keep in mind that this code is about a year old and was not written with Xcode 4.2 and its ARC feature in mind. Hence you will get compiler errors when you encounter [myVariable release] in the code. Just comment or delete those lines of code and it will run just fine.

PS: In case you do run into any trouble, there is a demo project that comes bundled with the gitHub download that may help you out.