UITableView 自动调整行约束在 iPhone 6Plus 上神秘地打破 [英] UITableView auto resizing row constraint breaking mysteriously on iPhone 6Plus

查看:27
本文介绍了UITableView 自动调整行约束在 iPhone 6Plus 上神秘地打破的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的 UITableViewCell,它有一个缩略图和一堆文本.行高配置为使用

自动计算

tableView.estimatedRowHeight = 129;tableView.rowHeight = UITableViewAutomaticDimension

行高应精确计算为 138 点.iPhone 5 上的一切看起来都很棒.但是,在 iPhone 6 Plus 上,自动行高会间歇性地失败,因为随机行会出现以下日志.

<代码>("<NSLayoutConstraint:0x17009ddd0 V:|-(20)-[scoop.ThumbnailImage:0x124d2a5a0] (Names: '|':UITableViewCellContentView:0x124e23200)>","<NSLayoutConstraint:0x17009de70 UITableViewCellContentView:0x124e23200.bottomMargin == scoop.ThumbnailImage:0x124d2a5a0.bottom + 20>","<NSLayoutConstraint:0x17009e780 V:[scoop.ThumbnailImage:0x124d2a5a0(90)]>","<NSLayoutConstraint:0x17009ef00 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x124e23200(138.333)]>")

日志的最后一行似乎说由于某种原因行高计算为 138.333 而不是 138.我一直在敲我的头一段时间,但我无法弄清楚为什么会这样.有人可以帮忙吗?

更新:这是我的表格视图单元格的样子.

更新 我无法从主存储库中获取代码,因为它是更大项目的一部分.但是我设法通过一个非常简单的理智项目重现了这个问题.请在

I have a custom UITableViewCell which has a thumbnail and bunch of text. The row height is configured to be calculated automatically using

tableView.estimatedRowHeight = 129;
tableView.rowHeight = UITableViewAutomaticDimension

The row height should be calculated as exactly 138 points. Everything looks great on the iPhone 5. However, on iPhone 6 Plus, the auto row height fails INTERMITTENTLY for random rows with the following log.

(
    "<NSLayoutConstraint:0x17009ddd0 V:|-(20)-[scoop.ThumbnailImage:0x124d2a5a0]   (Names: '|':UITableViewCellContentView:0x124e23200 )>",
    "<NSLayoutConstraint:0x17009de70 UITableViewCellContentView:0x124e23200.bottomMargin == scoop.ThumbnailImage:0x124d2a5a0.bottom + 20>",
    "<NSLayoutConstraint:0x17009e780 V:[scoop.ThumbnailImage:0x124d2a5a0(90)]>",
    "<NSLayoutConstraint:0x17009ef00 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x124e23200(138.333)]>"
)

The last line of the log seems to say that for some reason the row height was calculated as 138.333 instead of 138. I have been banging my head for a while now but I am unable to figure out why this is happening. Can some one please help?

Update: This is how my table view cell looks like.

UPDATE I couldn't get the code out of the main repo since its a part of a bigger project. But I have managed to reproduce the issue with a very simple sane project. Please find it here on github.

解决方案

This warning is telling you there's a conflict in your constraints. Reduce the priority of the height constraint to 999 and it will go away. Tested it in your Github project and worked perfectly.

这篇关于UITableView 自动调整行约束在 iPhone 6Plus 上神秘地打破的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆