Swift UITableViewAutomaticDimension is not working

前端 未结 4 919
时光取名叫无心
时光取名叫无心 2021-01-28 18:03

I have got a table in my Swift project like this

var tableView: UITableView! 
tableView = UITableView()
tableView.dataSource = self
tableView.delegate = self
ta         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-28 18:12

    You need intrinsic cell size for this to work. Delete heightForRowAt entirely. Your constraints in your cell should determine the cell size, this means your constraints should be at least pinned from top and bottom. Add the following code after setting the rowHeight:

    tableView.estimatedRowHeight = 250
    

提交回复
热议问题