夜の長さ、柔軟な高さのテーブルビューセル
私はものの(私はその中に含まれるテキストに基づいて高さが動的に拡張し、いくつかのUITableViewCellのを持っているが、文字のかつて特定の番号が入力されていることが表示されますまだこれをテストしていないので、正確な原因であるかどうかはわかりません)、高さは正しく計算されません。ここで
は、問題の原因となる例の文字列で、1000文字(ユーザーがに入力できるフィールドの最大長)に故意に切り捨て私のコードの関連部分です:
Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.
Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it.[1] Objective-C is the primary language used for Apple's Cocoa API, and it was originally the main language on NeXT's NeXTSTEP operating system. Generic Objective-C programs that do not use these libraries can also be compiled for any system supported by gcc or Clang.
Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.
Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it.[1] Objective-C is the primary language used for Apple's Cocoa API, and it was originally the main language on NeXT's NeXTSTEP operating system. Generic Objective-C programs that do no
これは、私cellForRowAtIndexPath:
...
cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
cell.detailTextLabel.font = [UIFont systemFontOfSize:15];
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.detailTextLabel.numberOfLines = 0;
から私は、次を使用してセルの高さを計算します。
- (CGFloat)tableView:(UITableView *)t heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellLabel;
NSString *cellText;
if (indexPath.section == 0) {
// This returns a small string such as 'Note'
cellLabel = [generalDetailsCellsArray objectAtIndex:indexPath.row];
// This returns the example string posted in the above block
cellText = [generalDetailsValuesArray objectAtIndex:indexPath.row];
}
--- snip ---
CGSize constraint = CGSizeMake(300.0f, 20000.0f);
CGSize labelSize = [cellLabel sizeWithFont:[UIFont boldSystemFontOfSize:15] constrainedToSize:constraint];
CGSize textSize = [cellText sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:constraint];
return (labelSize.height + textSize.height) + 12;
}
目立つ明白な騒ぎを見る人はいますか?
ありがとうございます。
セルのコンテンツビューから幅を読み取ることを検討することがあります。ユーザーがデバイスを回転させてセルの幅が広がると、それが役立ちます。 –