セルの高さと、内部に画像があるこのセル テキストの場所を決定する必要があります。これを実装する方法は?提案してください。サンクス。そして、次のように段落を個々のセルに分割したい:
1 に答える
0
コンテンツは動的であるため、1 つの方法として、heightForRowAtIndexPath (または同等のメソッド) が呼び出される前にセルの高さを計算し、それらの値を配列に格納することができます。
-(void)calculateCellHeights:(NSArray *)contentArray
{
self.heightArray = [[NSMutableArray alloc] initWithCapacity: contentArray.count];
for( MyCellContent *content in contentArray )
{
CGFloat totalHeight = 0;
totalHeight += content.image.size.height;
CGSize titleSize = [content.title sizeWithFont:self.myTitleFont];
totalHeight += titleSize.height;
CGSize textContentSize = [content.textContent sizeWithFont:self.myTextContentFont];
totalHeight += textContentSize.height;
[self.heightArray addObject:@(totalHeight)];
}
}
-(CGFloat) tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*) indexPath
{
return self.heightArray[[indexPath.row floatValue]];
}
これは、セクションが 1 つだけであり、NSAttributedStrings の代わりに通常のテキスト文字列が使用されていることを前提としており、インターフェイス要素間のパディングを処理しませんが、全体像はわかります。
于 2013-07-12T18:31:40.653 に答える