- An easy way to use pull-to-refresh
Add pod 'PDPullToRefresh'
to your Podfile or pod 'PDPullToRefresh', :head
if you're feeling adventurous.
Important note if your project doesn't use ARC: you must add the -fobjc-arc
compiler flag to UIScrollView+PDHeaderRefreshView.m
and UIScrollView+PDFooterRefreshView.m
in Target Settings > Build Phases > Compile Sources.
Drag the PDPullToRefresh/PDPullToRefresh folder into your project. Import PDPullToRefresh.h
(see sample Xcode project in /PDPullToRefresh
)
[tableView pd_addHeaderRefreshWithNavigationBar:YES andActionHandler:^{
// prepend data to dataSource, insert cells at top of table view
// call [tableView.pdHeaderRefreshView stopRefreshing] when done
}];
or if you want pull to refresh from the bottom
[tableView pd_addFooterRefreshWithNavigationBar:YES andActionHandler:^{
// prepend data to dataSource, insert cells at top of table view
// call [tableView.pdFooterRefreshView stopRefreshing] when done
}];
If you’d like to programmatically trigger the refresh (for instance in viewDidAppear:
), you can do so with:
[tableView.pdHeaderRefreshView startRefreshing];
The pull to refresh view can be customized using the following properties/methods:
@property (nonatomic, assign) CGFloat pdHeaderRefreshViewHeight;
@property (nonatomic, assign) CGFloat pdFooterRefreshViewHeight;
For instance, you would set the pdHeaderRefreshViewHeight
property using:
// Default is 80
tableView.pdHeaderRefreshViewHeight = 100;
PDPullToRefresh is Inspired by 半糖App、SVPullToRefresh
PDPullToRefresh is available under the MIT license. See the LICENSE file for more info.