iphone - Load more at the top of uitableview -
i need load more cell @ top of table populated custom cell, first time populate table ok, no overlap , no problem, if try load more cell cell appear wrong height , if try scroll cell change position randomly! code, mistake you?
- (nsinteger) tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { return [self.arraymessaggi count] + 1; } - (uitableviewcell *) tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (indexpath.row == 0) { if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; uilabel *labelload = [[uilabel alloc] initwithframe:cgrectmake(0, 0, 320, 44)]; [labelload setbackgroundcolor:[uicolor clearcolor]]; [labelload settextalignment:nstextalignmentcenter]; [labelload settext:[nsstring stringwithformat:@"%d - load more...",indexpath.row]]; [labelload settext:@"load more..."]; [labelload settag:3]; [cell.contentview addsubview:labelload]; } uilabel *labelload = (uilabel *)[cell.contentview viewwithtag:3]; [labelload settext:[nsstring stringwithformat:@"%d - load more...",indexpath.row]]; } else { if (cell == nil) { cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; pfobject *obj = [self.arraymessaggi objectatindex:indexpath.row - 1]; pfuser *user = [obj objectforkey:@"dautente"]; float height = [self getstringheight:[obj objectforkey:@"testomessaggio"] andfont:[uifont systemfontofsize:13]]; uilabel *labeluser = [[uilabel alloc] initwithframe:cgrectmake(20, 10, 280, 20)]; [labeluser setbackgroundcolor:[uicolor clearcolor]]; [labeluser settext:[user objectforkey:@"username"]]; [labeluser setfont:[uifont systemfontofsize:13]]; [labeluser settag:1]; [cell.contentview addsubview:labeluser]; } pfobject *obj = [self.arraymessaggi objectatindex:indexpath.row - 1]; pfuser *user = [obj objectforkey:@"dautente"]; uilabel *labeluser = (uilabel *)[cell.contentview viewwithtag:1]; [labeluser settext:[nsstring stringwithformat:@"%d - %@",indexpath.row,[user objectforkey:@"username"]]]; } return cell; } - (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath { float height = 44; if (indexpath.row > 0) { pfobject *obj = [self.arraymessaggi objectatindex:indexpath.row - 1]; nsstring *text = [obj objectforkey:@"testomessaggio"]; height = 30 + [self getstringheight:text andfont:[uifont systemfontofsize:13]] + 10; } return height; } - (void) setpulldowntorefresh { refreshcontrol = [[uirefreshcontrol alloc] init]; [refreshcontrol addtarget:self action:@selector(aggiornatabella:) forcontrolevents:uicontroleventvaluechanged]; [self.messagestableview addsubview:refreshcontrol]; } - (void) aggiornatabella:(uirefreshcontrol *)myrefreshcontrol { self.arraymessaggi = [nsmutablearray arraywitharray:objects]; self.messagestableview = [[uitableview alloc] init]; [self.messagestableview reload data]; }
Comments
Post a Comment