Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
844 views
in Technique[技术] by (71.8m points)

objective c - iOS: Dynamic Height For UITableViewCell

I'm using iOS9 XCode7 I need to change the height of cell Dynamically according to labelText Height

I have used:

self.tableView.rowHeight=UITableViewAutomaticDimension;

But it is not working for custom made cell. sizetoFit is removed in iOS9.

Please suggest something. Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Give your label constrains relative to the cell, top, bottom, left and right.

Than your cell size will grow with the content height.

also make your label multiline.(by setting Lines property to 0 in attribute inspector)

#pragma mark- Menu table Delegates 

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return UITableViewAutomaticDimension;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return UITableViewAutomaticDimension;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...