Add a new JSON Data on Tableview when it was scrolled in ios -



Add a new JSON Data on Tableview when it was scrolled in ios -

i create application utilize json info web services.and in web services contain 3 page.when add together info tableview fill first page info when scroll table view fill sec page info first page info removed want maintain both page data. in tableview want create load more listview android. please give me solution.i post code here.

- (void)viewdidload { pagenum=0; nsurl * url=[nsurl urlwithstring:[nsstring stringwithformat:@"http://www.truemanindiamagazine.com/webservice/news.php?page=%d",pagenum]]; nsdata * data=[nsdata datawithcontentsofurl:url]; nserror * error; nsdictionary *json = [nsjsonserialization jsonobjectwithdata:data options: nsjsonreadingmutablecontainers error: &error]; nslog(@"%@",json); self.imagesa=[json objectforkey:@"data"]; nslog(@"images,%@",self.imagesa); [self.spinner startanimating]; [self.table reloaddata]; } -(void)fetcheddata:(nsdata *)responsedata { nserror* error; nsdictionary *json = [nsjsonserialization jsonobjectwithdata:responsedata options:kniloptions error:&error]; self.imagesa=[json objectforkey:@"data"]; [self.table reloaddata]; nslog(@"images,%@",self.imagesa); } -(nsinteger)numberofsectionsintableview:(uitableview *)tableview { homecoming 1; } -(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { homecoming self.imagesa.count; } -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier=@"cell"; custumcell *cell=[tableview dequeuereusablecellwithidentifier:cellidentifier]; cell.selectionstyle=uitableviewcellselectionstylenone; if (cell == nil) { nsarray *nib=[[nsbundle mainbundle]loadnibnamed:@"custumcell" owner:self options:nil]; cell=[nib objectatindex:0]; } nsdictionary *dict = [self.imagesa objectatindex:indexpath.item]; nsstring *img2=[dict valueforkey:@"post_image"]; [cell.photoimage sd_setimagewithurl:[nsurl urlwithstring:[img2 stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]] placeholderimage:[uiimage imagenamed:@"hisoka.jpg"] options:sdwebimageprogressivedownload completed:^(uiimage *image, nserror *error, sdimagecachetype cachetype, nsurl *imageurl) { dispatch_async(dispatch_get_main_queue(), ^{ nslog(@"downloaded"); }); }]; nsstring *name=[dict valueforkey:@"post_title"]; cell.namelabel.text=name; nsstring *des=[dict valueforkey:@"post_content"]; cell.deslabel.text=des; nsdateformatter * dateformatter = [[nsdateformatter alloc]init]; [dateformatter setdateformat:@"yyyy-mm-dd hh:mm:ss"]; nsstring *date=[dict valueforkey:@"post_date"]; nsdate * datenotformatted = [dateformatter datefromstring:date]; [dateformatter setdateformat:@"d-mmm-yyyy"]; nsstring * dateformatted = [dateformatter stringfromdate:datenotformatted]; nslog(@"date %@",dateformatted); cell.datelabel.text=dateformatted; [self.spinner stopanimating]; self.spinner.hideswhenstopped=yes; homecoming cell; } -(void)scrollviewdidscroll:(uiscrollview *)scrollview { pagenum=pagenum+1; nslog(@"page number %d",pagenum); [self getdata]; } -(void)getdata { nsurl * url=[nsurl urlwithstring:[nsstring stringwithformat:@"http://www.truemanindiamagazine.com/webservice/news.php?page=%d",pagenum]]; dispatch_async(kbgqueue, ^{ jdata = [nsdata datawithcontentsofurl:url]; [self performselectoronmainthread:@selector(fetcheddata:) withobject:jdata waituntildone:yes]; }); }

please give me solution possible.

you have add together objects in array replacing array. that's why didnt data.

in viewdidload

self.imagesa = [[nsmutablearray alloc]init];

when response

-(void)fetcheddata:(nsdata *)responsedata { nserror* error; nsdictionary *json = [nsjsonserialization jsonobjectwithdata:responsedata options:kniloptions error:&error]; //check response nsarray class if ([[json objectforkey:@"data"] iskindofclass:[nsarray class]]) { // add together array objects in main array , reload table. nsarray *arr = (nsarray *)[json objectforkey:@"data"]; [self.imagesa addobjectsfromarray:arr]; [self.table reloaddata]; nslog(@"images,%@",self.imagesa); } }

maybe help you.

ios json uitableview

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -