iOS Tri-party-mjrefresh use

Source: Internet
Author: User

Mjrefresh is a very useful pull-down third-party library, the use is also very simple. GitHub Address: Https://github.com/CoderMJLee/MJRefresh.

Drop-down Refresh

The official example is very simple, the default use is as follows:

Self.tableView.header = [Mjrefreshnormalheader headerwithrefreshingblock:^{   //Enter the refresh state will automatically call this block}];  or //set callback (once in the refresh state, call Target's action, that is, call Self's Loadnewdata method) Self.tableView.header = [Mjrefreshnormalheader Headerwithrefreshingtarget:self refreshingaction: @selector (loadnewdata)];//immediately into the refresh state [Self.tableView.header Beginrefreshing];

End drop-down refresh:

Get the current dropdown refresh control and end the refresh status [Self.tableView.header endrefreshing];
Pull-up Refresh

The official gives the default example:

Self.tableView.footer = [Mjrefreshautonormalfooter footerwithrefreshingblock:^{//   Enter the refresh state will automatically call this block}]; Set the callback (once in the refresh state, call the action of target, that is, the Loadmoredata method that calls self) Self.tableView.footer = [Mjrefreshautonormalfooter Footerwithrefreshingtarget:self refreshingaction: @selector (loadmoredata)];

End pull-up refresh:

Get the current pull-up refresh control to end the refresh state [Self.tableView.footer endrefreshing];

From the above, we can see that, in general, when the page is made, we will use the drop-down refresh, and "immediately into the refresh state", after the network requests the data, the end of "drop-down refresh status." But the pull-up refreshes, there is no need to "immediately into the refresh state".

For more examples of use, please refer to the examples given by the official parameters, it is very convenient to use.

Below, give the actual usage code for a project:

njbilltableviewcontroller.m//njwisdomcard////Created by admin on 15/8/21.//Copyright (c) 2015 Weconex. All rights reserved.//#import "NJBillTableViewController.h" #import "NJBillListTableviewCell.h" #import "Common.h" # Import "NJHttpToolHandle.h" #import "mbprogresshud+nj.h" #import "NJAccountTool.h" #import "MJExtension.h" #import " MJRefresh.h "#import" NJAccountModel.h "#import" NJBillModel.h "@interface njbilltableviewcontroller ()/** * Billing Model */@ Property (Nonatomic, Strong) Nsmutablearray *billsframes;/** * pages */@property (nonatomic,assign) int pageIndex; @end @impl Ementation njbilltableviewcontroller-(Nsmutablearray *) billsframes{if (!_billsframes) {self.billsFrames = [NS]    Mutablearray array]; } return _billsframes;}        -(void) viewdidload {[Super viewdidload];        Integrated pull-down refresh control [self Setupdownrefresh]; Integrated pull-up refresh control [self Setupuprefresh];} /** * Integrated pull-up refresh control */-(void) setupuprefresh{self.tableView.footer = [Mjrefreshautonormalfooter FooterwithrefreshiNgtarget:self refreshingaction: @selector (Loadmorebills)];} /** * Integrated pull-down refresh control */-(void) setupdownrefresh{//Set callback (once in the refresh state, call Target's action, that is, call Self's Loadnewdata method) Self.tablevie        W.header = [Mjrefreshnormalheader headerwithrefreshingtarget:self refreshingaction: @selector (loadNewBills)]; Immediately enter the refresh status [Self.tableView.header beginrefreshing];}        /** * Load drop-down refresh Data */-(void) loadnewbills{_pageindex=1;//default Load First page [self.billsframes removeallobjects];//Remove all data        1. Take the user model from the sandbox Njaccountmodel *accountmodel=[njaccounttool Accountmodel];    2. Stitching request parameter Nsmutabledictionary *params = [Nsmutabledictionary dictionary]; params[@ "UserId"] =accountmodel.loginid;//login number params[@ "page"] =[nsstring stringwithformat:@ "%d", _pageindex];//pages pa        rams[@ "pagesize"] =[nsstring stringwithformat:@ "10"]; 3. Send Request [Njhttptoolhandle postwithservicecode:@ "Queryallbalance" Params:params success:^ (id responseobject) {i F ([responseobject[@ "ResultCode"] isequaltostring:@ "0000"]) {//Get the value array nsdictionary *dictlist = [Nsjsonserialization jsonobjectwithdata:[respo                     nseobject[@ "code"] jsondata] options:nsjsonreadingmutableleaves Error:nil];                        Convert the "Billing dictionary" array to the "Billing model" array nsarray *newbills = [Njbillmodel objectarraywithkeyvaluesarray:dictlist[@ "value"]];            Add the latest billing data to the front of the total group Nsrange range = Nsmakerange (0, Newbills.count);            Nsindexset *set = [Nsindexset indexsetwithindexesinrange:range];            [Self.billsframes insertobjects:newbills Atindexes:set];            [Self.billsframes insertobjects:newbills atindex:0];                        [Self.billsframes insertobjects:newbills atindexes:0];                        Refresh table [Self.tableview Reloaddata];        Get the current dropdown refresh control and end the refresh status [Self.tableView.header endrefreshing];        } else {[Self.tableView.header endrefreshing]; }} failure:^ (Nserror *error) {[Self.tableView.header endrefreshing]; }];} /** * Load pull-up refresh Data */-(void) loadmorebills{//1. Set page _pageindex++;//default load First page//2. Stitching Request Parameters Nsmutabledictionary *p    Arams = [Nsmutabledictionary dictionary]; params[@ "UserId"] =[njaccounttool accountmodel].loginid;//Login number params[@ "page"] =[nsstring stringwithformat:@ "%d", _        pageindex];//pages params[@ "pagesize"] =[nsstring stringwithformat:@ "10"]; 3. Send Request [Njhttptoolhandle postwithservicecode:@ "Queryallbalance" Params:params success:^ (id responseobject) {i F ([responseobject[@ "ResultCode"] isequaltostring:@ "0000"]) {//Get the value array Nsdictionary * Dictlist = [nsjsonserialization jsonobjectwithdata:[responseobject[@ "code"] jsondata] Options:                        Nsjsonreadingmutableleaves Error:nil];                        Convert the "Billing dictionary" array to the "Billing model" array nsarray *newbills = [Njbillmodel objectarraywithkeyvaluesarray:dictlist[@ "value"]]; Add more billing data to the totals group for the mostBack [Self.billsframes Addobjectsfromarray:newbills];                        Refresh table [Self.tableview Reloaddata];        Get the current dropdown refresh control and end the refresh status [Self.tableView.footer endrefreshing];        } else {[Self.tableView.footer endrefreshing];    }} failure:^ (Nserror *error) {[Self.tableView.footer endrefreshing]; }];}    -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} #pragma mark-table View Data source-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (    Nsindexpath *) indexpath{Njbilllisttableviewcell *cell = [Njbilllisttableviewcell Cellwithtableview:tableview];    Cell.billmodel=self.billsframes[indexpath.item]; return cell;} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {return Self.billsFrames.count;} -(CGFloat) TableView: (UITableView *) TableView HEIGHTFORrowatindexpath: (Nsindexpath *) indexpath{return 80;} @end

Use of iOS tri-party-mjrefresh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.