Important note if your project doesn’t use ARC: you must add the
-fobjc-arc compiler flag to
ODRefreshControl.m in Target Settings > Build Phases > Compile Sources.
If you are using ODRefreshControl in your app, drop me a line so I can add your app here!
ODRefreshControl is a “pull down to refresh” control for UIScrollView, like the one Apple introduced in iOS6, but available to anyone from iOS4 and up.
- Drag the
ODRefreshControl/ODRefreshControlfolder into your project.
- Add the QuartzCore framework to your project.
(see sample Xcode project in
Adding a refresh control to your table view
ODRefreshControl *refreshControl = [[ODRefreshControl alloc] initInScrollView:self.scrollView];
To know when the refresh operation has started, add an action method to the UIControlEventValueChanged event of the control
[refreshControl addTarget:self action:@selector(dropViewDidBeginRefreshing:) forControlEvents:UIControlEventValueChanged];
If you’d like to programmatically start the refresh operation, use
Remember to tell the control when the refresh operation has ended
ODRefreshControl can be customized using the following properties:
@property (nonatomic, strong) UIColor *tintColor; @property (nonatomic, assign) UIActivityIndicatorViewStyle activityIndicatorViewStyle; @property (nonatomic, strong) UIColor *activityIndicatorViewColor; // iOS5 or more
Using the iOS 6 control when possible
This will take a UITableViewController and configure it to use a UIRefreshController if it’s available (running iOS 6) or an ODRefreshController if it isn’t. One or the other will be returned, which you can then customize if necessary.
id *refreshControl = [ODRefreshControl setupRefreshForTableViewController:self withRefreshTarget:self action:@selector(dropViewDidBeginRefreshing:)];
ODRefreshControl is brought to you by Fabio Ritrovato and contributors to the project. If you have feature suggestions or bug reports, feel free to help out by sending pull requests or by creating new issues. If you’re using ODRefreshControl in your project, attribution would be nice.