iOS MJRefresh上拉加载更多
1.导入MJRefresh包
2.在类中引入:#import "MJRefresh.h"
3.添加footerView
添加加载更多的UI样式:
MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
myTableView.footer = footer;
[footer setTitle:@"正在加载中" forState:MJRefreshStateRefreshing];
[footer setTitle:@"" forState:MJRefreshStateIdle];
footer.stateLabel.font = [UIFontsystemFontOfSize:15.0f];
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;
}
posted on 2015-12-14 20:45 biggest fish 阅读(4576) 评论(0) 编辑 收藏 举报