標籤:
IOS開發之下拉重新整理和上拉載入更多1.簡介 常用的下拉重新整理和上拉載入更多的實現方式
(1)UIRefreshControl
(2)EGOTableViewRefresh
(3)AH3DPullRefresh
(4)MJRefresh
(5)自己實現
2.AH3DPullRefresh的使用 2.1 配置
1.匯入AH3DPullRefresh工程檔案
2.在工程TARGETS-> Build Phases-> Compile Sources->
搜尋UIScrollView+AH3DPullRefresh並在後面加上 “-fno-objc-arc”
3.添加頭UIScrollView+AH3DPullRefresh的標頭檔
#import "UIScrollView+AH3DPullRefresh.h"
2.2 使用(基於滿座網的執行個體)
1.添加下拉重新整理和上拉載入更多的方法
#pragma mark 下拉重新整理和上拉載入更多-(void)addPullRefreshAndPullLoadMore{ [_tableView setPullToRefreshHandler:^{ //從第一行資料開始下載 _offset = 1; [self startDownloadData]; }]; [_tableView setPullToLoadMoreHandler:^{ _offset += _pageSize; [self startDownloadData]; }];}
2. 下載資料:如果是下拉重新整理先清空所有的資料
//如果_offset = 1,重新重新整理 if (_offset == 1) { [_dataArray removeAllObjects]; }
載入完成新的資料之後結束重新整理並重新整理表格
//結束重新整理 [_tableView refreshFinished]; [_tableView loadMoreFinished]; [_tableView reloadData];
3.完整的代碼:
-(void)startDownloadData{ NSString *urlStr = [NSString stringWithFormat:MAIN_SHOP_URL,_city,_categotry,_offset,_pageSize]; _reauest = [[HttpRequest alloc]init]; [_reauest requestWithUrl:urlStr targe:self action:@selector(dealDownloadFinish:)];}-(void)dealDownloadFinish:(HttpRequest *)request{ NSString *str = [[NSString alloc]initWithData:request.data encoding:NSUTF8StringEncoding]; NSLog(@"%@",str); GDataXMLDocument *doc = [[GDataXMLDocument alloc]initWithData:request.data options:0 error:nil]; NSArray *list = [doc nodesForXPath:@"//promotion" error:nil]; //如果_offset = 1,重新重新整理 if (_offset == 1) { [_dataArray removeAllObjects]; } for (GDataXMLElement *promotion in list) { PromotionModel *model = [[PromotionModel alloc]init]; model.myid = [[[promotion elementsForName:@"id"] firstObject] stringValue]; model.name = [[[promotion elementsForName:@"name"] firstObject] stringValue]; [_dataArray addObject:model]; } //結束重新整理 [_tableView refreshFinished]; [_tableView loadMoreFinished]; [_tableView reloadData]; }
下載
IOS開發之下拉重新整理和上拉載入更多