Sina Weibo Project---Home technology point three. Pull-up refresh, implementation of pull-down loading (using the small Daisy with iOS)

Source: Internet
Author: User

I. Pull-up refresh, implementation of pull-down loading (implemented using the small daisy-band)

1. Drop-down Refresh

#pragma mark---the integrated * pull Refresh control-(void) Setupdownrefresh{//1. Adding a Refresh controlUirefreshcontrol *control = [[Uirefreshcontrol alloc] init];The uicontroleventvaluechanged event is triggered only if the user refreshes manually by pulling down[Control addtarget:self Action: @selector (Refreshstatechange:) forcontrolevents:uicontroleventvaluechanged]; [Self.tableview Addsubview:control];//2. Go to refresh status now (just show refresh status and not trigger Uicontroleventvaluechanged event)[Control beginrefreshing];//3. Loading data immediately[Self Refreshstatechange:control];}#pragma Mark---addtargat/action method for the integrated pull-down refresh control-(void) Refreshstatechange: (Uirefreshcontrol *) control{//1. Request ManagerAfhttprequestoperationmanager *mgr = [Afhttprequestoperationmanager manager];//2. Stitching Request ParametersAccountmodel *account = [Accounttool account];    Nsmutabledictionary *params = [Nsmutabledictionary dictionary]; params[@ "Access_token"] = Account.access_token;//Take out the front of the Weibo, (the latest Weibo, the most-id Weibo)Statusframe *FIRSTSTATUSF = [Self.statusframes firstobject]; if (FIRSTSTATUSF) {///If this parameter is specified, a microblog with an ID greater than since_id (that is, Weibo later than SINCE_ID) is returned, and the default is 0params[@ "since_id"] = firstStatusf.status.idstr; }//3. Sending requests[Mgr get:@ "Https://api.weibo.com/2/statuses/friends_timeline.json" Parameters:params success:^ ( Afhttprequestoperation *operation, Nsdictionary *responseobject) {//Convert the "microblog dictionary" array to the "Weibo model" arrayNsarray *newsstatuses = [Statusmodel objectarraywithkeyvaluesarray:responseobject[@ "statuses"];//Convert Hwstatus model to Hwstatusframe modelNsarray *newframes = [self stausframeswithstatuses:newsstatuses];//Add the latest Weibo data to the top of the total groupNsrange range = nsmakerange (0, Newframes.count);        Nsindexset *set = [Nsindexset indexsetwithindexesinrange:range]; [Self.statusframes insertobjects:newframes Atindexes:set];//Refresh table[Self.tableview Reloaddata];//End Refresh[Control endrefreshing];//Show the latest number of Weibo[Self showNewStatusCount:newsStatuses.count]; } failure:^ (Afhttprequestoperation *operation, Nserror *error) {NSLog (@ "request failed--%@", error);//End Refresh[Control endrefreshing]; }];}

------------------------------------------------------------------------------------------------------- ---
-----------------------------------------------------

2. Pull-Up load data

#pragma mark---integrated * pull Refresh control-(void) Setupuprefresh{Loadmorefooter *footer = [loadmorefooter footer];        Self.tableView.tableFooterView = footer; Uiscrollview *scrollview = [[Uiscrollview alloc] initWithFrame:self.tableView.frame];//Call pull-up loading method *************[Self scrollviewdidscroll:scrollview];    Footer.hidden = YES; }#pragma mark---Load more weibo data (used when loading previous data)-(void) Loadmorestatus{//1. Request ManagerAfhttprequestoperationmanager *mgr = [Afhttprequestoperationmanager manager];//2. Stitching Request ParametersAccountmodel *account = [Accounttool account];    Nsmutabledictionary *params = [Nsmutabledictionary dictionary]; params[@ "Access_token"] = Account.access_token;//Take out the front of the Weibo, (the latest Weibo, the most-id Weibo)Statusframe *LASTSTATUSF = [Self.statusframes lastobject]; if (LASTSTATUSF) {///If this parameter is specified, a microblog with an ID greater than since_id (that is, Weibo later than SINCE_ID) is returned, and the default is 0Long Long maxid = laststatusf.status.idstr.longlongvalue-1;    params[@ "max_id"] = @ (MAXID); }//3. Sending requests[Mgr get:@ "Https://api.weibo.com/2/statuses/friends_timeline.json" Parameters:params success:^ ( Afhttprequestoperation *operation, Nsdictionary *responseobject) {//Convert the "microblog dictionary" array to the "Weibo model" arrayNsarray *newsstatuses = [Statusmodel objectarraywithkeyvaluesarray:responseobject[@ "statuses"];//Convert Hwstatus model to Hwstatusframe modelNsarray *newframes = [self stausframeswithstatuses:newsstatuses];//Add more data to the last side of the array[Self.statusframes Addobjectsfromarray:newframes];//Refresh table[Self.tableview Reloaddata];//End Refresh (hide footer)Self.tableView.tableFooterView.hidden = YES; } failure:^ (Afhttprequestoperation *operation, Nserror *error) {NSLog (@ "request failed--%@", error);//End RefreshSelf.tableView.tableFooterView.hidden = YES; }];}

Sina Weibo Project---Home technology point three. Pull-up refresh, implementation of pull-down loading (using the small Daisy with iOS)

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.