最初のセルの他のセルの高さの合計が必要なため、セルの高さを下から上に計算する必要があります。最初に最後のセルの高さを計算し、次に最後のセルの 2 番目のセルなど、最後に最初のセルの高さを計算するにはどうすればよいですか。助けてください。私はここで非常に悪い構造をしています。私のコードはこのようなものです...上から下までの高さを示します。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0 && currentQuestion.graphic){
UIImage *img= [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:currentQuestion.graphic ofType:nil]];
self.currentQuestionImage=img;
[img release];
return (self.currentQuestionImage.size.height* [self zoomFactor])+10;
}else if ((indexPath.section==0 && !currentQuestion.graphic) || (indexPath.section==1 && currentQuestion.graphic)){
CGSize constSize = { self.view.frame.size.width, 20000.0f };
CGSize textSize = [currentQuestion.text sizeWithFont:[ThemeSettings fontUsedInQuestionCell] constrainedToSize:constSize lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = (textSize.height)+60.0;
return height<45.0?45.0:height;
}else if([self answerGraphic: indexPath]){
UIImage *img = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[self answerGraphic: indexPath] ofType:nil]];
[self.answerImages replaceObjectAtIndex:indexPath.section withObject:img];
int size = (img.size.height*0.50)+10;
[img release];
return size;
}else {
int answerIndex = currentQuestion.graphic?indexPath.section-2:indexPath.section-1;
Answer *a=[currentQuestion.answers objectAtIndex:answerIndex];
CGSize constSize = { 300.0f, 20000.0f };
CGSize textSize = [a.text sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:constSize lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = (textSize.height+textSize.height/3.0 )+10.0;
return height<55.0?55.0:height;
}
}
助けてください。