2017-02-03 7 views
0

クイック質問:私はUITableViewControllerを持っています、一般的な設定が正常に動作します。 私はちょうど間隔を微調整しようとしています。UITableViewController estimatedRowHeight with detailTextLabel

tableView.rowHeight = UITableViewAutomaticDimension 
tableView.estimatedRowHeight = 60 

私のデフォルトのセルのいくつかはdetailTextLabelstyle: .subtitle)を使用し、いくつかは、(style: .default)ない:私は呼んUITableViewControllerviewDidLoad

。 これが実行されると、セルは行の高さを調整していないように見えます。 特に、detailTextLabelが2行の場合、テキストが詰まって見えます。

私はtableView:heightForRowAtIndexPath:機能をオーバーライドすることを避けたかったですか? トリックはありますか?

ありがとうございました

+0

何が起こっているかのクイックスクリーンはありますか? :)高さのプロパティメソッドを使用する代わりに –

+0

高さの委任メソッドと同じtryを実行します。 Bczデリゲートメソッドは各セルを呼び出すので、各セルに異なる高さを設定できます。 –

+0

制約を使用します。メソッドを委譲します。 –

答えて

1

これは、システムセルのデフォルトの動作です。別の出力が必要な場合は、カスタムセルを作成し、必要に応じて上下の制約を与えます。幸運;)

+0

私はこれを試しましたが、 'topAnchor'と' bottomAnchor'を設定すると、ラベルは移動しましたが、セルの高さは変化しませんでした。 – Joseph

+0

セルにどのようなカスタマイズをしましたか?カスタムセルでは、自分のラベルを持つセル、両方のラベルに制約が設定されていました。正しい制約がある場合、セルのサイズが正しく変更されます。 –

+0

ok - 私は自分のカスタムUITableViewCellで 'self.textLabel'と' self.detailTextLabel'を使うべきではありませんか? – Joseph

0

私はあなたが直面した同じ問題を抱えていました。私はプログラム的に制約を加えました。あなたの問題を解決するのに役立つことを願っています。

- (void)awakeFromNib{ 
    [super awakeFromNib]; 
    for (NSLayoutConstraint *cellConstraint in self.constraints) { 
     [self removeConstraint:cellConstraint]; 
     id first_object = cellConstraint.first_object == self ? self.contentView : cellConstraint.first_object; 
     id seccondItem = cellConstraint.second_object == self ? self.contentView : cellConstraint.second_object; 
     NSLayoutConstraint *contentViewConstraint = 
     [NSLayoutConstraint constraintWithItem:first_object 
           attribute:cellConstraint.firstAttribute 
           relatedBy:cellConstraint.relation 
            toItem:seccondItem 
           attribute:cellConstraint.secondAttribute 
           multiplier:cellConstraint.multiplier 
            constant:cellConstraint.constant]; 
     [self.contentView addConstraint:contentViewConstraint]; 
    } 
} 
+0

多分私は既存の制約を削除する必要があります。まずそれを試みます。 – Joseph

+0

制約を削除するかどうかを教えてください。 – Nirmalsinh

+0

nope - セルの高さには影響しません。 – Joseph

関連する問題