With the release of Apple's iOS 6 came a software development kit (SDK) that introduced developers to many enhancements as well as plethora of new features. Every new iOS release gives developers an opportunity to evaluate their existing apps to determine if adding new functionality would be beneficial to an end user. One such feature - new in iOS 6 - is the ability for a developer to natively add the capability to update or refresh content on-demand. Specifically, a user can swipe downward to refresh the data in a table view (Figure A).
Figure A
The 'pull to refresh' concept is not new. We were first introduced to this capability in 2010 with the release of the Twitter for iPhone app. Until the release of iOS 6, however, we needed a third-party class - such as PullToRefresh - to enjoy this functionality. The technology rumor mill has had no shortage of stories as to why Apple delayed including this capability as part of the iOS SDK. Patent infringement seems to be the most popular public opinion supporting the reason this feature was not introduced earlier. The patent application describing a 'scrollable refresh trigger' can be previewed here. Regardless the reason, this capability now exists for all iOS developers to include in their own apps.
Implementing the UIRefreshControl
At first glance, the UIRefreshControl seems straightforward and simple. In reality, the control is not as easy to implement as nearly every other control in the iOS SDK. In true form, however, the refresh control handles quite a bit of heavy lifting behind the scenes. To use the UIRefreshControl on an existing table view, follow these steps:
- Add the UIRefreshControl to your table view (Interface Builder).
- Create a callback method to handle requests from the control (XCode Editor).
- Create an instance of the control, and programmatically 'wire' it all together.
Figure B
Figure C
Example code
In the viewDidLoad method of your table view controller, call the method to instantiate the UIRefreshControl. (Figure D)Figure D
Figure E
Figure F
Figure G
Make sure to call the endRefreshing method to stop the animation and prepare the interface for the next user interaction.
Editor's note: All of the code above is also available in this text file.Bottom line
Apple's inclusion of the UIRefreshControl gives developers a simple way to implement an interactive control that will allow users to update content. While it was common practice to include a button to perform this function, the refresh control approach leverages the device's ability to detect and handle a finger swipe. This is certainly more fluid and it seems to be a natural way to request information to be updated. The UIRefreshControl class reference contains a complete listing of the properties and instance methods for using the control.
Also read:
Full Bio
Gregory Dean is the CTO for the Wilen Group. He has spent the past 25 years in C-level positions setting the tone and direction of technology-driven services organizations. Gregory is constantly researching technologies and developing capabilities to differentiate services and product offerings in an aggressive and competitive industry. Mobile technologies and iOS app development are a big part of these efforts. He holds degrees in computer science and marketing. Gregory recently released an app for calculating ROI. The Marketography app also displays the latest news and articles from the Marketography.com blog.







