2012-02-28 19 views
0

夜の長さ、柔軟な高さのテーブルビューセル

私はものの(私はその中に含まれるテキストに基づいて高さが動的に拡張し、いくつかの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; 
} 

目立つ明白な騒ぎを見る人はいますか?

ありがとうございます。

答えて

0

他の誰かがこの質問に出くわしたら、私がしたのと同じ間違いをしないでください!

CGSize constraint = CGSizeMake(300.0f, 20000.0f)CGSize constraint = CGSizeMake(280.0f, 20000.0f)である必要があります。セル内のセルのパディングを考慮していないため、セルに描画されたときの幅よりも広いラベル幅が計算されていました。

要約:グループ化されたUITableViewCell内のラベルの幅は280です!

+0

セルのコンテンツビューから幅を読み取ることを検討することがあります。ユーザーがデバイスを回転させてセルの幅が広がると、それが役立ちます。 –

0

正確なエラーシナリオを作成していないようです。行の高さを計算するコードを心配する前に、問題を例題で正確に定義してください。あなたは何らかの方法で誤算しているという点ではおそらく正しいでしょうが、問題を再現するために必要な情報をまとめた後で初めて、問題であることが分かります。

+0

ありがとうございます。私は明白なことを試みました(私はもともとcellForRowでsystemFontを使用していましたが、fontNamed:@ "Helvetica"という計算で、単純なものだと思っていました)、数字を確認するために歩いてきました。このシナリオは再現するためのものです。 – Greg

関連する問題