ios - in UITableView first entry and last entry switching record data when loading from server -


i developing app display data server in parallax type uitableview, , here code. loading great, cell data(image, etc) keep switching 1 cell another.

- (void)viewdidload {     [self hasinternet];     self.tableview.datasource = self;     self.tableview.delegate = self;     [self loaddata];     self.edgesforextendedlayout=uirectedgenone;     self.extendedlayoutincludesopaquebars=no;     self.automaticallyadjustsscrollviewinsets=no;     [super viewdidload]; } - (void)viewwillappear:(bool)animated {     [self scrollviewdidscroll:nil];     [super viewwillappear:animated];     [self loaddata];     self.tableview.datasource = self;     self.tableview.delegate = self; } - (void) loaddata{     name = @"name";     email = @"email";     thumbnail = @"thumbnail";     myobject = [[nsmutablearray alloc] init];     nsdata *jsonsource = [nsdata datawithcontentsofurl:[nsurl urlwithstring:@"http://url.php"]];     id jsonobjects = [nsjsonserialization jsonobjectwithdata:jsonsource options:nsjsonreadingmutablecontainers error:nil];     (nsdictionary *datadict in jsonobjects) {         nsstring *title_data = [datadict objectforkey:@"fname"];         nsstring *title_data2 = [datadict objectforkey:@"lname"];         nsstring *fulname = [nsstring stringwithformat:@"%@ %@", title_data, title_data2];         nsstring *email = [datadict objectforkey:@"email"];         nsstring *thumbnail_data = [datadict objectforkey:@"img"];         thumbnail_data = [nsstring stringwithformat:@"http://url/upload/%@",thumbnail_data];         dictionary = [nsdictionary dictionarywithobjectsandkeys: fulname, name, email, email, thumbnail_data, thumbnail, nil];         [myobject addobject:dictionary];     } } - (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     return 1; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return myobject.count; }  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {     static nsstring *cellidentifier = @"parallaxcell";     jbparallaxcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier];     if (cell == nil) {         cell=[[jbparallaxcell alloc]initwithstyle:               uitableviewcellstylesubtitle reuseidentifier:cellidentifier];     }     nsdictionary *tmpdict = [myobject objectatindex:indexpath.row];     nsmutablestring *text;     text = [nsmutablestring stringwithformat:@"%@",[tmpdict objectforkeyedsubscript:name]];     nsmutablestring *mail;     mail = [nsmutablestring stringwithformat:@"%@",[tmpdict objectforkeyedsubscript:email]];     nsmutablestring *images;     images = [nsmutablestring stringwithformat:@"%@ ",[tmpdict objectforkey:thumbnail]];     nsurl *url = [nsurl urlwithstring:[tmpdict objectforkey:thumbnail]];     dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{         nsurl *url = [nsurl urlwithstring:[tmpdict objectforkey:thumbnail]];         nsdata *data = [nsdata datawithcontentsofurl:url];         dispatch_async(dispatch_get_main_queue(), ^{             cell.parallaximage.image = [[uiimage alloc]initwithdata:data];         });     });     cell.titlelabel.text = [nsstring stringwithformat:@"%@",text];     cell.subtitlelabel.text = [nsstring stringwithformat:@"%@",mail];     return cell; } - (void)scrollviewdidscroll:(uiscrollview *)scrollview {     nsarray *visiblecells = [self.tableview visiblecells];         (jbparallaxcell *cell in visiblecells) {         [cell cellontableview:self.tableview didscrollonview:self.view];     } } 

when compile it, shows data keep switching 1 cell another. appreciated. thanks

because uitableview reuse cell when scroll down or previous cell gone tableview bound reuse. it's image view has image when use last time have clear first imageview. put line

cell.parallaximage.image = nil; 

before dispatch queue

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -