ios - CollectionView 约束打破
问题描述
我有一个collectionView,每个单元格都包含一个tableView。灰色部分应该是collectionView。
正如您可以清楚地看到,当前的表视图不遵守约束集。我从控制台收到以下错误。
The behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and
bottom values, minus the content insets top and bottom values.
The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7f80fd28e420>, and it
is attached to <UICollectionView: 0x7f80fc08f800; frame = (0 114; 375 664); clipsToBounds = YES;
autoresize = RM+BM; gestureRecognizers = <NSArray: 0x600000d6c4b0>; layer = <CALayer: 0x6000003beee0>;
contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 0, 0};
layout: <UICollectionViewFlowLayout: 0x7f80fd28e420>; dataSource: <BizTiz.EventDetailController: 0x7f80fa0b7800>>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
我该如何解决?此外,当我将此 collectionView 推送到堆栈上时,会有一个小的滞后。我猜这可能是由于先前的错误。
解决方案
意识到我的错误......
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: view.frame.height - 114)
}
我将高度设置为view.frame.height
. 我忘了减去顶部的额外高度。
推荐阅读
- c# - 线程安全的异步方法
- formula - LibreOffice 如何在公式/方程式中写出“大小”一词?
- swift - 使用 audiokit 的多个 MIDI 输出
- php - Laravel - 如何只显示那些有产品的类别?
- angular - 刷新的角度路由问题
- google-bigquery - 在 BigQuery 中获取所有时间唯一值
- javascript - 如何允许内联 JS 脚本使用 Nonce 进行 CSP
- vue.js - 映射数组并将项目保存到Vue中的其他数组
- javascript - 未捕获的 RangeError:输入掩码中超出了最大调用堆栈大小
- python - Discord.py Dont Rename Voice Channel