Swift UITableViewAutomaticDimension not working

空扰寡人 提交于 2020-01-26 02:30:16

问题


I am trying to get auto re-sizing of my table cells working. I have simplified my cells so that I just have a single label. When running my code in the simulator on a 4s it works fine, but when running on a real 4s device I get a strange gray square over most of the table, and lots of logging with messages like:

Will attempt to recover by breaking constraint

My understanding of constraints still isnt great, but I have setup a top, bottom, leading and trailing margin on my label. I have the following in viewDidLoad:

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

I always return UITableViewAutomaticDimension from heightForRowAtIndexPath

Is there something else I need to do to get auto sizing of table cells working on a real device?

I've tried adding calls to setNeedsUpdateConstraints and updateConstraintsIfNeeded as described in this link, but it didnt help: Using Auto Layout in UITableView for dynamic cell layouts & variable row heights

来源:https://stackoverflow.com/questions/34889476/swift-uitableviewautomaticdimension-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!