How to make UITableView's height dynamic with autolayout feature?

后端 未结 5 1336
抹茶落季
抹茶落季 2021-01-31 03:32

I am using autolayout in Xcode 5.

I set the table view\'s height to Greater than or equal to 200px. I want that it has dynamic size. Because sometimes it will have many

5条回答
  •  花落未央
    2021-01-31 03:56

    create your cell by xib or storyboard. give it's outlet's contents. now call it in CellForRowAtIndexPath. eg. if you want to set cell height according to Comment's label text.enter image description here

    so set you commentsLbl.numberOfLine=0;

    then in ViewDidLoad

     self.table.estimatedRowHeight = 44.0 ;
    self.table.rowHeight = UITableViewAutomaticDimension;
    

    and now

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

    voila ............ you did it....

提交回复
热议问题