簡體   English   中英

CollectionView 約束打破

[英]CollectionView Constraints breaking

我有一個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 推送到堆棧上時,會有一個小的滯后。 我猜這可能是由於先前的錯誤。

請在 UICollectionViewDelegateFlowLayout 中設置布局。

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

意識到我的錯誤......

   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 我忘了減去頂部的額外高度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM