In iOS development, we often use a drop-down refresh to load new data. iOS is born with this method, the following on iOS comes with a drop-down Refresh method to simple operation.
1, in the TableView, a open software, we call the drop-down refresh event.
-(void) viewdidload { [super viewdidload]; Integrated refresh control [self Setuprefresh]; } /** * Integrated pull-down refresh */-(void) setuprefresh{ //1. Add Refresh control Uirefreshcontrol *control=[[uirefreshcontrol alloc]init ]; [Control addtarget:self Action: @selector (Refreshstatechange:) forcontrolevents:uicontroleventvaluechanged]; [Self.tableview Addsubview:control]; 2. Immediately enter the refresh state, and will not trigger the Uicontroleventvaluechanged event [Control beginrefreshing]; 3. Load Data [self Refreshstatechange:control];}
2, Next, we will implement Refreshstatechange this method, in the inside display data and close the drop-down refresh.
/** * Uirefreshcontrol into the refresh state: Load the latest data */-(void) Refreshstatechange: (Uirefreshcontrol *) control{ //3. Send Request Afhttprequestoperationmanager *mgr = [Afhttprequestoperationmanager manager]; [Mgr get:@ "Https://api.weibo.com/2/statuses/public_timeline.json" Parameters:nil success:^ (afhttprequestoperation *operation, Nsdictionary *responseobject) { //1. Get data, process data, pass data to TableView, such as: //Add up-to-date microblog data to the front of the total group// Nsrange range = nsmakerange (0, Newstatuses.count);// Nsindexset *set = [Nsindexset indexsetwithindexesinrange: range];// [self.statuses insertobjects:newstatuses atindexes:set]; 2. Refresh the table [Self.tableview reloaddata]; 3. End Refresh [Control endrefreshing]; } failure:^ (Afhttprequestoperation *operation, Nserror *error) { // End refresh refresh, in order to avoid Network load failure, always show the refresh status error [Control endrefreshing];}
iOS drop-down refresh