gpt4 book ai didi

ios - UITableViewAutomaticDimension 的约束错误

转载 作者:搜寻专家 更新时间:2023-11-01 06:28:35 25 4
gpt4 key购买 nike

我很难处理动态高度自定义 tableView 单元格。

所以我得到了“无法同时满足约束条件。”警告(但只是有时,就像千分之一)


我认为 UITableViewAutomaticDimension 给出了问题。在示例中,它期望高度为 88.3333,但它可能不正确。 (但大部分时间都有效,我不明白发生了什么)

我做错了什么,有人可以帮忙吗?什么都试过了..

代码:

var cellHeights: [IndexPath : CGFloat] = [:]
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cellHeights[indexPath] = cell.frame.size.height

if indexPath.row == UserWorldMessagesStore.shared.worldMessages.count - 1 && userWorldMessagesCanLoadMore == true {
loadOlderOwnWorldMessages()
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
if cellHeights[indexPath] != nil {
return CGFloat(Float(cellHeights[indexPath] ?? 0.0))
}
else {
return UITableViewAutomaticDimension
}
}

警告:

2018-05-19 19:58:54.879876+0200 PipeTest[3378:1282243] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x1c0297fc0 V:|-(10)-[UILabel:0x125d5db40'Heyy'] (active, names: '|':UIView:0x125d03400 )>",
"<NSLayoutConstraint:0x1c0298010 V:[UILabel:0x125d5db40'Heyy']-(10)-| (active, names: '|':UIView:0x125d03400 )>",
"<NSLayoutConstraint:0x1c0298100 PipeTest.profilePictureImageView:0x125d56fc0.height == 22 (active)>",
"<NSLayoutConstraint:0x1c0298240 UIView:0x125e58150.height == 27 (active)>",
"<NSLayoutConstraint:0x1c0298600 PipeTest.profilePictureImageView:0x125d56fc0.top == UITableViewCellContentView:0x125d50850.topMargin (active)>",
"<NSLayoutConstraint:0x1c02986a0 V:[PipeTest.profilePictureImageView:0x125d56fc0]-(3)-[UIView:0x125d03400] (active)>",
"<NSLayoutConstraint:0x1c02988d0 UIView:0x125e58150.bottom == UITableViewCellContentView:0x125d50850.bottomMargin (active)>",
"<NSLayoutConstraint:0x1c0298970 V:[UIView:0x125d03400]-(7)-[UIView:0x125e58150] (active)>",
"<NSLayoutConstraint:0x1c0299230 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x125d50850.height == 88.3333 (active)>"
)

最佳答案

完整的警告文本应该包括类似

的内容
Will attempt to recover by breaking constraint  
<NSLayoutConstraint:somePointer V:some constraint>

将该约束的优先级降低到 999 应该会使此警告消失。

原因就在那一行:

<NSLayoutConstraint:0x1c0299230 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x125d50850.height == 88.3333   (active)>

这是一个系统提供的约束,它告诉表格 View 单元格的高度应该是多少,它的值基于您从 estimatedHeightForRowAt 返回的值。在计算正确的像元大小(最终会正确计算)之前会抛出警告,因此只需降低一些其他约束的优先级是安全的,因此系统提供的约束优先。

关于ios - UITableViewAutomaticDimension 的约束错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50428115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com