06 --- pull and refresh the data drop-down; pull and load more implementations

Source: Internet
Author: User

Taking my recent microproject as an example, let's talk about how to pull and load data from pull-down refresh.

 

Page loading data:

# Pragma mark-load Weibo data-(void) loadstatusdata {_ statusesframe = [nsmutablearray array]; // Add [statusmanage getstatuseswithsendsinceid: 0 maxid: 0 success: ^ (nsarray * statues) {for (status * s in statues) {statuscellframe * f = [[statuscellframe alloc] init]; F. status = s; [_ statusesframe addobject: F];} [self. tableview reloaddata];} failure: ^ (nserror * error) {nslog (@ "% @", error) ;}];}

 

Pull up Refresh:

# Pragma mark-load the latest data-(void) loadnewdata :( mjrefreshbaseview *) refreshview {// 1. retrieve the ID statuscellframe * SCF = [_ statusesframe firstobject]; long since = [[SCF status] id]; // 2. get Weibo data after sence [statusmanage getstatuseswithsendsinceid: Since maxid: 0 success: ^ (nsarray * statues) {// 1 ". get the latest Weibo data and add it to the corresponding frame nsmutablearray * newstatusframearray = [[nsmutablearray alloc] init]; for (status * s in statues) {statuscellframe * f = [[statuscellframe alloc] init]; F. status = s; [newstatusframearray addobject: F];} // 2. insert the array to the front of the first microblog [_ statusesframe insertobjects: newstatusframearray atindexes: [nsindexset indexsetwithindexesinrange: nsmakerange (0, newstatusframearray. count)]; // 3. refresh the table [self. tableview reloaddata]; // 4. let the refresh control stop refreshing status [refreshview endrefreshing]; [self shownewstatuscount: newstatusframearray. count];} failure: ^ (nserror * error) {[refreshview endrefreshing];}

 

Pull down to load more:

# Pragma mark-load more data-(void) loadmoredata :( mjrefreshbaseview *) refreshview {// 1. last microblog ID statuscellframe * f = [_ statusesframe lastobject]; long last = [F. status id]; // 2. get Weibo data [statusmanage getstatuseswithsendsinceid: 0 maxid: Last-1 success: ^ (nsarray * statues) {// 1. calculate its frame nsmutablearray * oldstatusframearray = [nsmutablearray array] while obtaining the latest Weibo data; for (status * s in statues) {statuscellframe * f = [[statuscellframe alloc] init]; F. status = s; [oldstatusframearray addobject: F];} // 2. insert newframes to the end of the old data [_ statusesframe addobjectsfromarray: oldstatusframearray]; // 3. refresh the table [self. tableview reloaddata]; // 4. let the refresh control stop refreshing status [refreshview endrefreshing]; [self shownewstatuscount: oldstatusframearray. count];} failure: ^ (nserror * error) {[refreshview endrefreshing];}

 

TIPS:

Load more from the drop-down list. The obtained array can be directly added to the end of the last object of the array on the current display page,

// 2. Insert newframes to the end of the old data [_ statusesframe addobjectsfromarray: oldstatusframearray];

 

Pull up and refresh, the entire array must be inserted before the first object of the current display page array, because the data returned by Sina is larger according to the shorter time.

      

// 2. Insert the array into the front of the first microblog [_ statusesframe insertobjects: newstatusframearray atindexes: [nsindexset indexsetwithindexesinrange: nsmakerange (0, newstatusframearray. Count)];

 

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.