下拉刷新和分页(加载更多)已经成为当代iOS应用中的普遍功能。然而许多库只提供下拉刷新或分页功能,而不是两者都提供。因此,我们决定编写我们自己的自定义表格管理器,它可以处理这两个功能。现在您只需编写视图,就可以忘记实际的下拉刷新和分页细节。
OPHTableController是一个用于iOS的表格视图管理器,只需一行代码即可为您的表格视图提供下拉刷新和分页功能(包括默认视图)。
self.tableController = [[OPHTableController alloc]
initWithScrollView:self.tableView delegate:self];
它使用了SSPullToRefresh来完成所有的下拉刷新功能。
pod 'OPHTableController', :git => 'https://github.com/ophio/OPHTableController.git', :branch => 'master'
It handles all the pagination functionality.
It handles all the pull to refresh functionality.
It manages both the above classes and your viewcontroller or another manager should only interact with this class.
- (void)viewDidLoad {
[super viewDidLoad];
self.tableController = [[OPHTableController alloc]
initWithScrollView:self.tableView delegate:self];
}
OPHTableControllerDelegate,
OPHPullToRefreshCustomView
/* this method will by default add pull to refresh and loader into the table. */
- (instancetype)initWithScrollView:(UIScrollView*)scrollView delegate:(id<OPHTableControllerDelegate>)delegate;
/* this method can be used if you want to selectively add pull to refresh OR loader into the table. */
- (instancetype)initWithScrollView:(UIScrollView*)scrollView delegate:(id<OPHTableControllerDelegate>)delegate withPullToRefresh:(BOOL)isPullToRefresh withLoadMore:(BOOL)isLoadMore;
/* this method will stop the pull to refresh, have to call explicitly */
- (void)pullToRefreshFinishLoading;
/* this method should be called when using a custom view; you can handle the animation of the custom loader in the delegate methods */
- (void)configCustomLoadMoreView:(UIView*)customView;
/* this method should be called when using a custom pull to refresh view; you can handle the animation of the custom loader and respond to the state changes in the delegate methods */
- (void)configCustomPullToRefreshView:(UIView<OPHPullToRefreshCustomView>*)customView;
/* it should return YES if you want to use load more functionality */
- (BOOL)loadMoreShouldStartLoading:(OPHLoadMore *)loadMore;
/* you can perform API calls i.e. update data source; you should call the completion block explicitly after you have updated the data source. */
- (void)loadMoreDidStartLoading:(OPHLoadMore *)loadMore withCompletionBlock:(OPHCompletionBlock)block;
@optional
/* you can perform further actions after the loader stops */
- (void)loadMoreDidFinishLoading:(OPHLoadMore *)loadMore;
查看SSPullToRefresh的文档。
/* this method should be called when using a custom view; you can handle the animation of the custom loader in the delegate methods */
- (void)configCustomLoadMoreView:(UIView*)customView;
OPHTableController是在MIT许可证下可用的。有关更多信息,请参阅LICENSE文件。