【发布时间】:2018-04-16 07:21:53
【问题描述】:
我有一个 UITableViewCell,里面有 collectionView。约束是非常简单的前导 0 ,尾随 0 ,前 10 和后 10 并且 UICollection 视图的高度约束是 160 。将 IBOutlet 连接到高度约束。在行的单元格中,我正在更新高度约束。
但在调试时出现错误
行的单元格代码是
func videoCell(for tableView:UITableView ,with indexPath:IndexPath , videos:[VideoCollectionViewCellConfigure] ) -> VideoTableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "VideoTableViewCell", for: indexPath) as! VideoTableViewCell
cell.videoConfigurators = videos
cell.collectionCellClickedBlock = self.videoCollectionCellClicked(_:_:)
if videos.count > 0 {
let video = videos[0]
cell.videoCollectionViewHeightConstraint.constant = video.height
}
cell.videoCollectionView.reloadData()
return cell
}
2018-04-16 12:42:10.815998+0530 CineBee[5280:74417] [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:0x6000006878a0 UICollectionView:0x7f86109c4c00.height
== 180 (active)>",
"<NSLayoutConstraint:0x604000885870 V:[UICollectionView:0x7f86109c4c00]-(10)-| (active, names: '|':UITableViewCellContentView:0x7f8615803ca0 )>",
"<NSLayoutConstraint:0x604000888de0 V:|-(10)-
[UICollectionView:0x7f86109c4c00] (active, names: '|':UITableViewCellContentView:0x7f8615803ca0 )>",
"<NSLayoutConstraint:0x60400088dde0 'UIView-Encapsulated-Layout-Height'
UITableViewCellContentView:0x7f8615803ca0.height == 180.5 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000006878a0
UICollectionView:0x7f86109c4c00.height == 180 (active)>
【问题讨论】:
-
显示整个错误日志.. 它告诉您哪些约束存在冲突
-
也可以试试wtfautolayout.com
-
此外,解释一下如何定义 tableView 单元格的高度。它是静态高度,还是计算的自动布局?显示相关代码
-
你应该调整单元格的大小来保存视频,调整单元格的大小使用
heightForRowAtIndexPath -
在 HeightForRow 我正在返回 UITableViewAutomaticDimension。
标签: ios uitableview autolayout