- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我很难处理动态高度自定义 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/
我有一个 TableView ,其中包含由代码创建的动态单元格。 在 IOS 7 中,为了确保单元格完全显示,我覆盖了方法 heightForRowAtIndexPath 在 ios8 中覆盖这个方法
我正在使用 UITableViewAutomaticDimension 制作 TableView 但由于某种原因,最后一个空白单元格之后的“额外”空白单元格与最后一个带有文本的单元格的尺寸相同。我希望
我的表格有这段代码 (_filters = UITableView) - (void)viewDidLoad { // table data set here ... _filters
我正在制作一个带有文本帖子的应用程序,但我意识到很多文本帖子会很长,所以我添加了一个显示全部和更少按钮,但是当你按下它时,有时单元格会消失,你向上滚动然后它跳到单元格的中间。这是它的样子,因为它很难解
我有一个显示所有用户更新的 feedVC。我正在从 firebase 检索数据,并希望根据帖子长度自动设置高度。问题是,即使从 heightForRowAt 返回 UITableViewAutomat
我有一个项目使用 iOS 的默认动态字体。因此,我使用 UITableViewAutomaticDimension 作为高度。我以编程方式执行所有操作,因此我为我的自定义单元格设置了约束。 我对约束和
我的 Swift 项目中有这样一张表 var tableView: UITableView! tableView = UITableView() tableView.dataSource = self
图像显示在其中一个单元格中。 图像的约束条件如下: heightForRow 中此单元格的高度设置为 UITableViewAutomaticDimension。但是图像从底部被砍掉了。如何解决这个问
我添加了一个表格 View ,我在单元格中显示图像。我还添加了这段代码: tableView.estimatedRowHeight = 175 tableView.rowHeight = UITabl
关于 UITableView 的 UITableViewCell 的动态高度有很多问题。但是我无法解决我的问题。 我有这个表格单元格创建代码: class UINoteTabelViewCell: U
我正在以编程方式为日历应用程序制作一个表格 View ,并且需要根据它们包含的文本调整我的表格 View 单元格的大小。我正在尝试使用自动布局,但由于某种原因我无法让它工作 - (void)view
我很难处理动态高度自定义 tableView 单元格。 所以我得到了“无法同时满足约束条件。”警告(但只是有时,就像千分之一) 我认为 UITableViewAutomaticDimension 给出
好的,我在使用 tableview 创建动态单元格时遇到了问题。我的图像崩溃了,看起来像这样。当描述很长时效果很好,但当描述很短时效果不佳。 图像约束为:width = 120,height = 16
我正在尝试使用 UITableViewAutomaticDimension,但我无法在不引起 NSLayoutAutomaticSizeConstraint... 问题的情况下让单元格具有完整宽度和正
我对 UITableViewAutomaticDimension 有疑问: 在我的表格 View 中,我有多个以编程方式创建的 ImageView ,它们具有计算的高度: override func
我在 tableView 中使用 UITableViewAutomaticDimension 并且它工作正常,但是当加载表时,我需要单元格的行大小。表的。可能吗? 提前致谢。 最佳答案 使您的 Vie
只要我不尝试启用自动调整大小,我的单元格就可以正常显示。当我在我的 viewController 中添加用于自动调整大小的两行时,个人资料图片、用户名和日期下的所有内容都会消失(该单元格应该看起来像
是否可以为单元格设置最小高度?我使用动态: tableView.estimatedRowHeight = 83.0 tableView.rowHeight = UITableViewAutomatic
首次加载 TableView 时,所有可见单元格都是估计的行高。当我向下滚动时,单元格会自动调整大小,当我向上滚动时,最初 estimatedRowHeight 的单元格会自动调整大小。 一旦单元格自
我试图将最后一个tableView行的高度设置为与其他行不同。我不想创建一个新的单元格等,而是想从该单元格的高度“剪切”10px。由于我设置了高度的自动尺寸,因此无法使用恒定值。 它是这样的: tab
我是一名优秀的程序员,十分优秀!