简体   繁体   English

CollectionView 约束打破

[英]CollectionView Constraints breaking

I have a collectionView and each cell contains a tableView inside it.我有一个collectionView,每个单元格都包含一个tableView。 The gray portion is supposed to be the collectionView.灰色部分应该是collectionView。 在此处输入图像描述

But when I run the app, I get something like this但是当我运行应用程序时,我得到了这样的东西在此处输入图像描述

As you can clearly see that the table view present doesn't stick to the constraints set.正如您可以清楚地看到,当前的表视图不遵守约束集。 I get the following errors from the console.我从控制台收到以下错误。

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.

How do I fix this?我该如何解决? Also when I push this collectionView onto the stack, there is a small lag.此外,当我将此 collectionView 推送到堆栈上时,会有一个小的滞后。 I am guessing this might be due to the previous error.我猜这可能是由于先前的错误。

Please set layout in the UICollectionViewDelegateFlowLayout.请在 UICollectionViewDelegateFlowLayout 中设置布局。

   func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: <cell_width>, height: <cell_height>)
    }

Realized my mistake....意识到我的错误......

   func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: view.frame.width, height: view.frame.height - 114)
    }

I was setting the height as view.frame.height .我将高度设置为view.frame.height I had forgotten to subtract the extra height at top.我忘了减去顶部的额外高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM