iOS 8.3 breaks automatic cell height

百般思念 提交于 2019-12-10 18:56:47

问题


Long time reader, first time poster.

I use automatic cell height with auto layout in my app. In iOS 8.3 and 8.4, this appears to be broken. I have a sample project. When built in 8.2 or lower, it works properly. The cell heights are determined by Autolayout. When built in 8.3 or 8.4 it doesn't work. I have searched online and I don't see anyone posting about this issue.

Take a look at the screenshots below. Any help is appreciated.

Cell Height Project ZIP

Screenshot comparison http://jeffburg.com/skitch/CellHeightProjectComparison.png

Thanks! -Jeff


回答1:


I checked your code and found the problem.

Reading through AppCodas article about self-sizing cells, it looks like you should use estimatedRowHeight when using UITableViewAutomaticDimension (haven't used it myself, cannot confirm). So either remove the following line:

self.tableView.rowHeight = UITableViewAutomaticDimension

or add (if your cell height will be changing based on content):

self.tableView.estimatedRowHeight = 122;



回答2:


I used to have the same issue on my iOS >8.3 project. I fixed your sample project by implementing the delegate methods instead of setting the rowHeight in viewDidLoad. This is definitely a bug related to UITableView, so you did nothing wrong.




回答3:


Add this method on your delegate:

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


来源:https://stackoverflow.com/questions/30011948/ios-8-3-breaks-automatic-cell-height

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