1.導入MJRefresh包orm
2.在類中引入:#import "MJRefresh.h"get
3.添加footerViewanimation
添加加載更多的UI樣式:it
MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];io
myTableView.footer = footer;table
[footer setTitle:@"正在加載中" forState:MJRefreshStateRefreshing];import
[footer setTitle:@"" forState:MJRefreshStateIdle];變量
footer.stateLabel.font = [UIFontsystemFontOfSize:15.0f];select
footer.automaticallyHidden = YES;方法
加載數據:
定義全局變量:int32_t _pageNumber;
定義loadMoreData方法
- (void)loadMoreData{
UIEdgeInsets edge = _tableView.contentInset;
edge.bottom = 44;
[UIView animateWithDuration:0.2 animations:^{
_tableView.contentInset = edge;
}];
[self loadDataWithPage:_pageNumber];
}
4.數據返回處理,排重
//排重數據
for (Model *Model1 in resultArray) {
BOOL isExist = NO;
for (Model *Model in _publish) {
if (Model.positionId == Model1.positionId) {
isExist = YES;
break;
}
}
if (!isExist) {
[_publish addObject:Model1];
}
}
結束刷新
if(_tableView.footer.isRefreshing){
[_tableView.footer endRefreshing];
}
//當數據小於5條,沒有下拉刷新
if (_publishPositions.count < 5) {
[_tableView.footer noticeNoMoreData];
_tableView.footer.hidden = YES;
}