2016-08-01 4 views
0

私はテキストビューのカスタムUITableViewCellを持っています。動的にtextViewに従ってUITableViewCell hightを増やすことができません

textViewの高さはテキストによって増加します。

テキストビューに合わせてセルの高さを上げる方法を理解できません。あなたは、この手順を実行する必要があり、そのために

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NotificationCell *cell = (NotificationCell *)[tableView dequeueReusableCellWithIdentifier:@"cell"]; 
    if (cell == nil) { 
     NSArray *ary = [[NSBundle mainBundle]loadNibNamed:@"NotificationCell" owner:self options:nil]; 
     cell = [ary objectAtIndex:0]; 

    } 
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:[NotificationArray objectAtIndex:indexPath.section]]; 
    cell.title_lbl.text=[dict objectForKey:@"event_title"]; 
    cell.description_lbl.text=[dict objectForKey:@"description"]; 
    [cell.description_lbl sizeToFit]; 
    [cell sizeToFit]; 

    return cell; 
} 
+0

[UILabelテキストの量に応じてテーブルビューセルの高さを上げる]可能な複製(http://stackoverflow.com/questions/36544115/increase-height-of-tableview-cell-according-to-amount-of-ユーラベルテキスト) –

答えて

1

は、ここに私のコードです。あなたのstoryboardまたは.xib

ステップ1

使用Autolayoutと動的であるラベルのためのあなたの制約は次のようにあるべきことを確認してください。あなたのViewControllerのviewDidLoad

enter image description here

ステップ2

あなたは、このようなestimatedRowHeightを提供する必要があります。ステップ3

とのtableViewデリゲートheightForRowAtIndexPathで

self.tblViewOutlet.rowHeight = UITableViewAutomaticDimension; 
self.tblViewOutlet.estimatedRowHeight = 50.0; //any height which is like minimum 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension; } 

を確認してくださいあなたのUILabel(ここで私はdescription_lbl推測)プロトタイプセルプロパティnumberOfLines0でなければなりません。

ご希望の場合はご利用ください。 :)

ハッピーコーディング!

関連する問題