上拉刷新组件(AUDragLoadingView)和下拉刷新组件(Aupullloadingview)提供上拉或下拉页面时的加载样式。
以下非业务定制化的控件,都需要切换为下拉(Aupullloadingview)或上拉(AUDragLoadingView)组件。
CommonUI 包含 ODRefreshControl、APCircleRefreshControl、EGORefreshTableHeaderView、APNextPagePullView 四个组件。
效果图
接口说明
AUDragLoadingView.h
// // AUDragLoadingView.h // AntUI // #import <AntUI/AntUI.h> @interface AUDragLoadingView : AUPullLoadingView @end
AUPullLoadingView.h
详情请参见 下拉刷新控件。
代码示例
//
// APRefreshTableViewController.m
// UIDemo
//
#import "APRefreshTableViewController.h"
@interface APRefreshTableViewController ()
{
BOOL _headerReloading;
BOOL _footerReloading;
BOOL _isHeader;
}
@property(nonatomic,strong)AUPullLoadingView *refreshHeaderView;
@property(nonatomic,strong)AUDragLoadingView *refreshFooterView;
@property(nonatomic, strong) UITableView *tableView;
@property(nonatomic, strong) NSMutableArray* listArray;
@end
@implementation APRefreshTableViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSArray *array = @[@"0",
@"1",
@"2",
@"3",
@"4",
@"5",
@"6",
@"7",
@"8",
@"9",
@"10",
@"11",
@"12",
@"13",
@"14",
@"15",
@"16",
@"17",
@"18",
@"19"];
self.listArray = [NSMutableArray arrayWithArray:array];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.edgesForExtendedLayout = UIRectEdgeNone;
// self.navigationItem.rightBarButtonItem = [APUtil getBarButtonWithTitle:RightBarButtonTitle target:self];
self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.backgroundColor = [UIColor colorWithRGB:0xf5f5f9];
self.tableView.separatorColor = [UIColor colorWithRGB:0xdddddd];
[self.view addSubview:self.tableView];
if (_refreshHeaderView == nil) {
AUPullLoadingView *view = [[AUPullLoadingView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height)];
view.delegate = self;
[view ShowLastPullDate:YES];
[view ShowStatusLabel:NO];
[self.tableView addSubview:view];
_refreshHeaderView = view;
}
[_refreshHeaderView refreshLastUpdatedDate];
if (_refreshFooterView == nil) {
AUDragLoadingView *view = [[AUDragLoadingView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 48)];
view.delegate = self;
[view setPullUp:@"上拉加载更多信息"];
[view setRelease:@"放松"];
self.tableView.tableFooterView = view;
_refreshFooterView = view;
}
_isHeader = YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma tableview datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _listArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"RefreshCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (nil == cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = _listArray[indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods
- (void)reloadHeaderTableViewDataSource{
// should be calling your tableviews data source model to reload
// put here just for demo
NSInteger first = [_listArray[0] integerValue] - 1;
[_listArray insertObject:[NSString stringWithFormat:@"%li",(long)first] atIndex:0];
_headerReloading = YES;
}
- (void)doneLoadingHeaderTableViewData{
// model should call this when its done loading
_headerReloading = NO;
[_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
[self.tableView reloadData];
}
- (void)reloadFooterTableViewDataSource{
// should be calling your tableviews data source model to reload
// put here just for demo
NSInteger count = [_listArray count];
NSInteger last = [_listArray[count-1] integerValue] + 1;
[_listArray addObject:[NSString stringWithFormat:@"%li",(long)last]];
_footerReloading = YES;
}
- (void)doneLoadingFooterTableViewData{
// model should call this when its done loading
_footerReloading = NO;
[_refreshFooterView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
[self.tableView reloadData];
}
#pragma mark -
#pragma mark UIScrollViewDelegate Methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentInset.top + scrollView.contentOffset.y < 0) {
_isHeader = YES;
} else {
_isHeader = NO;
}
if (_isHeader) {
[_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
} else {
[_refreshFooterView egoRefreshScrollViewDidScroll:scrollView];
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (_isHeader) {
[_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
} else {
[_refreshFooterView egoRefreshScrollViewDidEndDragging:scrollView];
}
}
#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods
- (void)egoRefreshTableHeaderDidTriggerRefresh:(AUPullLoadingView*)view
{
if (_isHeader) {
[self reloadHeaderTableViewDataSource];
[self performSelector:@selector(doneLoadingHeaderTableViewData) withObject:nil afterDelay:2.0];
} else {
[self reloadFooterTableViewDataSource];
[self performSelector:@selector(doneLoadingFooterTableViewData) withObject:nil afterDelay:2.0];
}
}
- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(AUPullLoadingView*)view
{
if (_isHeader) {
return _headerReloading;
} else {
return _footerReloading; // should return if data source model is reloading
}
}
- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(AUPullLoadingView*)view{
return [NSDate date]; // should return date data source was last changed
}
@end
文档内容是否对您有帮助?