未定义UICollectionViewFlowLayout的行为-UICOLLECTION VIEW CHANGES SIZES。 XCODE-SWIFT

我正在尝试启动一个应用程序,并在决定是使用情节提要还是对其进行编程编码。我正在研究从网上下载的项目来决定。

我使用UICollectionviews显示数据。 当我以编程方式打开viewcontroller时,一切正常,单元格完美显示了图像。但是,当我启动一个情节提要板并将情节提要板中的视图控制器链接到我的快速文件代码时,集合视图图像小于整个屏幕,并且一旦刷新视图,该图像对于整个屏幕就变得太大了,我得到了这个错误:

2019-11-09 11:14:02.087688+1300 testapp[22869:4508359] the item width must be less than the width of the UICollectionView minus the section insets left and right values,minus the content insets left and right values.
2019-11-09 11:14:02.087788+1300 testapp[22869:4508359] Please check the values returned by the delegate.
2019-11-09 11:14:02.088547+1300 testapp[22869:4508359] The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x7f9c65d191e0>,and it is attached to <UICollectionView: 0x7f9c6602ee00; frame = (0 0; 414 808); clipsToBounds = YES; autoresize = W+H; autoresizesSubviews = NO; tintColor = UIExtendedSRGBColorSpace 0.357511 0.488406 0.724745 1; gestureRecognizers = <NSArray: 0x60000376f420>; layer = <CALayer: 0x600003947180>; contentOffset: {0,-60}; contentSize: {414,565}; adjustedContentInset: {0,83,0}; layout: <UICollectionViewFlowLayout: 0x7f9c65d191e0>; dataSource: <Storefront.HomeController: 0x7f9c65c0e180>>.
2019-11-09 11:14:02.092875+1300 testapp[22869:4508359] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

此处提供用于设置collectionview的代码:

 class HomeController: mycollectionViewController {

   override func viewDidLoad() {
    super.viewDidLoad()
    collectionView?.backgroundColor = .white
    collectionView?.register(imageCell.self,forCellWithReuseIdentifier: imageCell.cellId)
    collectionView?.backgroundView?.alpha = 0
    let refreshControl = UIRefreshControl()
    refreshControl.addTarget(self,action: #selector(handleRefresh),for: .valueChanged)
    collectionView?.refreshControl = refreshControl
    fetchImages()
}

override func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int {
    return images.count
}

    override func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: imageCell.cellId,for: indexPath) as! imageCell
        if indexPath.item < images.count {
            cell.image = images[indexPath.item]
        }
        cell.delegate = self
        return cell
    }
}



 //MARK: - UICollectionViewDelegateFlowLayout

extension HomeController: UICollectionViewDelegateFlowLayout {

func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath) -> CGSize {
    let dCell = imageCell(frame: CGRect(x: 0,y: 0,width: view.frame.width,height: 1000))
    dCell.image = images[indexPath.item]
    dCell.layoutIfNeeded()
    var height: CGFloat = dCell.header.bounds.height
    height += view.frame.width
    height += 24 + 2 * dCell.padding 
    height += dCell.captionLabel.intrinsicContentSize.height + 8
    return CGSize(width: view.frame.width,height: height)
}
}

我已将此代码链接到的Viewcontroller是Collectionviewcontroller。该应用程序不会崩溃,我只会收到错误消息,并且collectionview会更改大小。

我在这里搜索解决方案,但没有任何效果。我看不到使用情节提要或以编程方式打开此控制器有何不同?

请帮助!

luvlu 回答:未定义UICollectionViewFlowLayout的行为-UICOLLECTION VIEW CHANGES SIZES。 XCODE-SWIFT

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3134750.html

大家都在问