ios - Issue with running through NSArray - Obj C -
i have nsdictionary object
returned server. using populate information on uitableviewcontroller
. issue when processing each object returned, seems duplicate, lets 2 objects returned. make 2 table cells
first object's data. lets title section both objects "yes" , "no". populate list first object title show, yes , yes.
here happens:
controller loaded:
- (void)viewdidload { [super viewdidload]; // make request server [self makerequests]; }
runs request server stores information follow:
nsdictionary* json = [nsjsonserialization jsonobjectwithdata:returndata //1 options:kniloptions error:&error]; self.googleplacesarrayfromafnetworking = [json objectforkey:@"requested_data"]; [self.tableview reloaddata];
than cellforrowatindexpath
runs:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"timelinecell"; fbgtimelinecell *cell = (fbgtimelinecell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; if (!cell) { cell = [[fbgtimelinecell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; cell.usernamelabel.text = [_googleplacesarrayfromafnetworking[indexpath.row] objectforkey:@"name"]; <!-- here title example talking happens [cell setselectionstyle:uitableviewcellselectionstylenone]; [cell inittimelinecell]; } uiimage *img = [uiimage imagenamed:[nsstring stringwithformat:@"%d.jpg", indexpath.row]]; cell.photoview.image = img; return cell; }
here googleplacesarr...
@property (strong, nonatomic) nsarray *googleplacesarrayfromafnetworking;
here numberofrowsinsection
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [self.googleplacesarrayfromafnetworking count]; }
suggestions thoughts? let me know if need else.
update:
also think important note using this:
https://github.com/seitk/fb-gallery
as base populating returned data.
this happens when cell gets recycled if tableview:cellforrowatindexpath:
method fails set of members of recycled objects.
that precisely happens in code: when cell recycled, never set usernamelabel.text
, recycled value may shown multiple times.
you should move code sets cell's properties outside of if
statement fix problem:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"timelinecell"; fbgtimelinecell *cell = (fbgtimelinecell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; if (!cell) { cell = [[fbgtimelinecell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; [cell setselectionstyle:uitableviewcellselectionstylenone]; [cell inittimelinecell]; } // line moved "if" statement cell.usernamelabel.text = [_googleplacesarrayfromafnetworking[indexpath.row] objectforkey:@"name"]; uiimage *img = [uiimage imagenamed:[nsstring stringwithformat:@"%d.jpg", indexpath.row]]; cell.photoview.image = img; return cell; }
Comments
Post a Comment