IOS development pull-down refresh and pull-up loading more, ios Loading
IOS development pull-down refresh and pull-up loading more 1. Introduction to common pull-down refresh and pull-up loading more implementation methods
(1) UIRefreshControl
(2) EGOTableViewRefresh
(3) AH3DPullRefresh
(4) MJRefresh
(5) self-implementation
2. Use 2.1 configuration of AH3DPullRefresh
1. Import the AH3DPullRefresh project file
2. Go to the project TARGETS-> Build Phases-> Compile Sources->
Search UIScrollView + AH3DPullRefresh and add "-fno-objc-arc"
3. Add the header file UIScrollView + AH3DPullRefresh
#import "UIScrollView+AH3DPullRefresh.h"
2.2 usage (full-seat network-based instances)
1. Add pull-down refresh and pull-up to load more methods
# Pragma mark pull-down refresh and pull-up load more-(void) addPullRefreshAndPullLoadMore {[_ tableView setPullToRefreshHandler: ^ {// start download_offset = 1 from the first line of data; [self startDownloadData];}]; [_ tableView setPullToLoadMoreHandler: ^ {_ offset + = _ pageSize; [self startDownloadData];}
2. download data: if it is a pull-down refresh, clear all data first.
// If _ offset = 1, refresh if (_ offset = 1) {[_ dataArray removeAllObjects];}
After loading the new data, refresh and refresh the table.
// Stop refreshing [_ tableView refreshFinished]; [_ tableView loadMoreFinished]; [_ tableView reloadData];
3. complete code:
-(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]; // If _ offset = 1, refresh 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];} // end refresh [_ tableView refreshFinished]; [_ tableView loadMoreFinished]; [_ tableView reloadData];}
Download