1. Create the ScrollView when the cell initializes, then add ImageView to the ScrollView, and finally dynamically calculate the height of the scrollview while reusing the cell
All in all, initialize the Create control to be placed in the cell's init, assign the value to the outside of Init, or each cycle will be repeatedly created ImageView view
-(uitableviewcell *) TableView: (uitableview *) TableView Cellforrowatindexpath: (nsindexpath *) indexpath{
UITableViewCell *cell=[tableview dequeuereusablecellwithidentifier:@ "Cellid"];
if (cell==nil) {
cell=[[UITableViewCell alloc]initwithstyle: uitableviewcellstyledefault Reuseidentifier:@ "Cellid"];
scrolling View
self. ScrollView=[[uiscrollview alloc]init];
self. ScrollView. Tag=9;
Create a picture for ScrollView
cgfloat scrollviewwidth=[uiscreen mainscreen]. Bounds. Size. Width-up;
int Hang=[self. Imagesarray count]%3==< Span class= "S5" >0int) [self. Imagesarray count]/3:( Span class= "S6" >int) [self. Imagesarray count]/3+1
int imgwidth= (scrollviewwidth-)/3;
for (int i=0; i
for (int j=0; j<3; j + +) {
if (i*3+j==self. Imagesarray. Count) {
break;
}
uiimageview< Span class= "S1" > *imgview=[[uiimageview alloc ]initwithframe:cgrectmake (j* (imgwidth+< Span class= "S5" >55
Imgview. image=[UIImage imagenamed: [self. Imagesarray objectatindex: i*3+j];
[self. ScrollView addsubview: Imgview];
}
}
[Cell. contentview addsubview:self. ScrollView];
}
else{
Self. ScrollView= (uiscrollview *) [cell. Contentview viewwithtag:9];
}
calculate uilabelcontent height based on number of words ( modified )
cgfloat labelwidth=[uiscreen mainscreen]. Bounds. Size. Width-up;
nsdictionary *attrs=@{nsfontattributename:self. Labelcontent. Font};
cgsize maxsize=cgsizemake(labelwidth, maxfloat);
cgsize size=[self. Labelcontent. Text boundingrectwithsize: maxSize options:nsstringdrawinguseslinefragmentorigin attributes: attrs context:nil]. Size;
self. Labelcontent. Frame=CGRectMake(all, size. Width, size. Height);
//scrollview as the picture grows
cgfloat Scrollviewwidth=[uiscreen mainscreen]. Bounds. Size. Width-26;
int Hang=[self< Span class= "S1". imagesarray count]%3==0int) [self. Imagesarray count]/3:( Span class= "S6" >int) [self. Imagesarray count]/3+1
int imgwidth= (scrollviewwidth-)/3;
self. ScrollView. BackgroundColor=[uicolor lightgraycolor];
self. Scrollview. Frame=cgrectmake (13 89+size. Height+101) *5);
}
iOS development add pictures dynamically in cell solve recurring layer problems