iOS Tips: Pull to Refresh in less than 30 seconds

Using Xcode

Paul Jackson
Jul 4, 2014 · 3 min read

Pull to Refresh is a common idiom on iOS—originally made popular by the folks at Twitter. This approach to refreshing a view has become so ubiquitous Xcode now enables you to add this feature to your views in just a few simple steps. This post is about how to do exactly that… in 30 seconds!

Before we start the clock, create a new project in Xcode—containing a storyboard with a UITableViewController and a backing code file for the view controller; with that in place, we’re ready to start.

  • In Xcode, in Main.storyboard, in the Document Outline pane, select View Controller, and then select the Attribute Inspector on the Utilities pane.
  • In Attribute Inspector, in Table View Controller, change Refreshing from Disabled to Enabled.
From Disabled
To Enabled

Notice in the Document Outline pane that there is now a new control called Refresh Control.

Refresh Control
  • If not already visible, open the Assistant Editor for the View Controller.
The Assistant Editor
  • In Document Outline, press CTRL, and then click Refresh Control and drag to the buddy file, release to complete the drag operation when the cursor is between the @interface and @end code elements.
CTRL + drag to the Assistant buddy file
  • Create a new Action, called refresh, and change the Type from id to UIRefreshControl.
Create an Action

This generates a method at the end of the code file called refresh: that passes in one parameter of type UIRefreshControl.

  • Scroll to the end of the code file, and then add your code to refresh your data source.
Refresh your data source

After your data source has finished loading data you must send a endRefreshing message to the UIRefreshControl to restore the UI back to normal, as you can see on line 50 above.

  • Stop the clock!

I have created a sample project that you can use if you want to see this approach in action.

iOS App Development

Stories and technical tips about building apps for iOS…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store