iphone - same View different size at cell,how to reuse the cell -


- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     // return number of rows in section.       nslog(@"[listarr count]=%d",[listarr count]);     return [listarr count];    }  // customize appearance of table view cells. - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {      postcount *post=[listarr objectatindex:indexpath.row];   //     nsstring *cellidentifier = [nsstring stringwithformat: @"cell_%d_%@",indexpath.row,post.foreignid]; //     //    uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; //    if (cell == nil) { //        cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier]; //         //        nslog(@"indexpath.row++++++++=%d",indexpath.row); //         //         //     //    }else{ ////        [[cell.contentview viewwithtag:indexpath.row+1000] removefromsuperview]; //       timelinegraphicview *gview=(timelinegraphicview *)[cell viewwithtag:indexpath.row+1000]; //         [gview removefromsuperview]; //        gview=nil; //    } //    //     //     //    timelinegraphicview *gview=[[timelinegraphicview alloc]init]; //    gview.tag=indexpath.row+1000; //    gview.delegate=self; // //    [cell.contentview addsubview:gview]; //     //    int allheight =[modelclass returngraphicviewheight_timeline:post]; //    gview.frame=cgrectmake(0, 0, 320, allheight); //    [gview setviewstyle:post]; //     // //    gview.lab_time.text=[modelclass intervalsincenow:post.when btime:0]; //     //    post=nil; //     //    return cell;      static nsstring *cellidentifier = @"timelinegraphicviewcell";      timelinegraphicviewcell *cell = (timelinegraphicviewcell*)[tableview dequeuereusablecellwithidentifier:cellidentifier];     if(cell==nil){          cell = [[timelinegraphicviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:cellidentifier] ;      }   //     //    int allheight =[modelclass returngraphicviewheight_timeline:post]; //    cell.frame=cgrectmake(0, 0, 320, allheight);       //时间     if (cell.btime==1) {         cell.lab_time.text=[modelclass intervalsincenow:post.when btime:1 ];     }else{         cell.lab_time.text=[modelclass intervalsincenow:post.when btime:0];     }       cell.imageview_t.hidden=no;     //    imageview_t.isroundicon=yes;     if(![globalvariable isblankstring:post.who.avatarbig])     {          [cell.imageview_t setimagewithurl:[nsurl urlwithstring:post.who.avatarbig]                     placeholderimage:[uiimage imagenamed:@"default_user.png"]];      }     else{         cell.imageview_t.image=[uiimage imagenamed:@"default_user.png"];     }       cell.imageicon.image=[uiimage imagenamed:[modelclass returnimage_source:post.source]];     cell.whoscreenname.text=post.who.screenname;       cgsize size_mywhat =[modelclass heightfortextview:[uifont systemfontofsize:15] withtext:post.what weith:250];       cell.mywhat.frame=cgrectmake(50, 25, 250, size_mywhat.height);     cell.mywhat.text=[nsstring stringwithformat:@"%@",post.what];     cell.mywhaticon.frame=cell.mywhat.frame;       if(![globalvariable isblankstring:post.img_small])     {          cgsize size_myimageview=cgsizemake(80, 80);          cell.myimageview.frame=cgrectmake(50, 30+size_mywhat.height, size_myimageview.width, 80);         cell.myimageview.hidden=no;           [cell.myimageview setimagewithurl:[nsurl urlwithstring:post.img_small]                     placeholderimage:[uiimage imagenamed:@"default_user.png"]];           uibutton * myimagebtn=[[uibutton alloc]init];         myimagebtn.frame= cgrectmake(50, 30+size_mywhat.height, size_myimageview.width, 80);         [myimagebtn addtarget:self action:@selector(my_imag_btnclick:) forcontrolevents:uicontroleventtouchupinside]; //        myimagebtn.tag=self.tag-1000;         [cell addsubview:myimagebtn ];       }      if ([post.sourcetweet.what length]>0) {         cell.whowhat.text=[nsstring stringwithformat:@"@%@: %@",post.sourcetweet.who.screenname,post.sourcetweet.what];      }      cgsize size_whowhat =[modelclass heightfortextview:[uifont systemfontofsize:14] withtext:cell.whowhat.text weith:250];      cell.whowhat.frame=cgrectmake(10, 10, 250, size_whowhat.height);      if(![globalvariable isblankstring:post.sourcetweet.img_small])     {            cgsize size_whoimageview=cgsizemake(80, 80);         cell.whoimageview.frame=cgrectmake(30, 15+size_whowhat.height, size_whoimageview.width, 80);         cell.whoimageview.hidden=no;         [cell.whoimageview setimagewithurl:[nsurl urlwithstring:post.sourcetweet.img_small]                      placeholderimage:[uiimage imagenamed:nil]];           uibutton * whoimagebtn=[[uibutton alloc]init];         int myimageheight=0;         if (cell.myimageview.frame.size.height>0) {             myimageheight=5+80;         }         whoimagebtn.frame=cgrectmake(30+42, 40+size_mywhat.height+size_whowhat.height+myimageheight, 80, 80);         whoimagebtn.backgroundcolor=[uicolor clearcolor];         [whoimagebtn addtarget:self action:@selector(who_imag_btnclick:) forcontrolevents:uicontroleventtouchupinside]; //        whoimagebtn.tag=self.tag-1000;         [cell addsubview:whoimagebtn ];     }        if (size_whowhat.height<20) {         cell.whobgview.hidden=yes;     }else{          int myimageheight=0;         if (cell.myimageview.frame.size.height>0) {             myimageheight=5+80;         }          cell.whobgview.frame=cgrectmake(42, 25+size_mywhat.height+myimageheight, 270, 20+size_whowhat.height+cell.whoimageview.frame.size.height);      }       return cell;  } 

and timelinegraphicviewcell

  - (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier {     self = [super initwithstyle:style reuseidentifier:reuseidentifier];     if (self) {         // initialization code          imageview_t=[[uiimageview alloc]initwithframe:cgrectmake(5, 5, 40, 40)];         imageview_t.hidden=yes;           imageview_t.layer.cornerradius = 5;         imageview_t.layer.maskstobounds = yes;         //给图层添加一个有色边框         imageview_t.layer.borderwidth = 0.8;         imageview_t.layer.bordercolor = [[uicolor colorwithred:230.0/255 green:230.0/255 blue:230.0/255 alpha:1.0] cgcolor];          [self addsubview:imageview_t];           imageicon=[[uiimageview alloc]initwithframe:cgrectmake(295, 5, 16, 16)];         [self addsubview:imageicon];            self.lab_time = [[uilabel alloc] initwithframe:cgrectmake(210, 5, 80, 20)];         self.lab_time.textcolor=[uicolor graycolor];         self.lab_time.font=[uifont systemfontofsize:12];         self.lab_time.textalignment=uitextalignmentright;         self.lab_time.backgroundcolor=[uicolor clearcolor];         [self addsubview: self.lab_time];           whoscreenname = [[uilabel alloc] initwithframe:cgrectmake(60, 5, 145, 20)];         whoscreenname.textcolor=[uicolor blackcolor];         whoscreenname.font=[uifont systemfontofsize:18];         whoscreenname.linebreakmode = uilinebreakmodetailtruncation;         whoscreenname.numberoflines = 0;         whoscreenname.backgroundcolor=[uicolor clearcolor];         [self addsubview:whoscreenname];           mywhat = [[uitextview alloc] init];         mywhat.textcolor=[uicolor blackcolor];          mywhat.backgroundcolor=[uicolor clearcolor];         [mywhat setscrollenabled:no];         [mywhat seteditable:no];         mywhat.datadetectortypes=uidatadetectortypelink;         [mywhat setcancancelcontenttouches:no];         [self addsubview:mywhat];          mywhaticon=[[uiview alloc]init];         [self addsubview:mywhaticon];           myimageview=[[uiimageview alloc]init];         myimageview.hidden=yes; //         myimageview.compressed_img=1;         [self addsubview:myimageview];             whobgview=[[uiimageview alloc]init];         //        [whobgview setimage:[[uiimage imagenamed:@"popup.png"] stretchableimagewithleftcapwidth:0 topcapheight:30]];         whobgview.image = [[uiimage imagenamed:@"timeline_rt_border_t.png"] stretchableimagewithleftcapwidth:130 topcapheight:7];          [self addsubview:whobgview];           whowhat = [[uitextview alloc] init];         whowhat.textcolor=[uicolor blackcolor];          whowhat.backgroundcolor=[uicolor clearcolor];         [whowhat setscrollenabled:no];         [whowhat seteditable:no];          whowhat.datadetectortypes=uidatadetectortypelink;//url         [whowhat setcancancelcontenttouches:no];         [whobgview addsubview:whowhat];           whoimageview=[[uiimageview alloc]init];         whoimageview.hidden=yes;         //         whoimageview.backgroundcolor=[uicolor yellowcolor]; //        whoimageview.compressed_img=1;         [whobgview addsubview:whoimageview];          mywhat.font=[uifont systemfontofsize:15];         whowhat.font=[uifont systemfontofsize:14];     }     return self; } 

some view maybe hide,and view size may different,i use above code,but cell @ mistake location.

create method in timelinegraphicviewcell calculate it's height given data. , in viewcontroller create temp cell global variable , use in heightforrowatindexpath calculate height of each cell using it's given data.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -