sizeForItemAtIndexPath

sizeForItemAtIndexPath

本文介绍了从未调用CollectionView sizeForItemAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我抓狂!我有一个UICollectionViewController,如下所示:

This is driving me crazy! I have a UICollectionViewController as shown below:

class PhrasesCompactCollectionViewController: UICollectionViewController

正在调用numberOfSections和cellForItemAt,但从不调用sizeForItemAtIndexPath。我在其他地方使用相同的确切代码,它正确触发。我正在使用Xcode 8 Beta 6.

The numberOfSections and cellForItemAt are being called but the sizeForItemAtIndexPath is never called. I am using the same exact code somewhere else and it fires correctly. I am using Xcode 8 Beta 6.

func collectionView(collectionView: UICollectionView,
                        layout collectionViewLayout: UICollectionViewLayout,
                        sizeForItemAtIndexPath indexPath:  NSIndexPath) -> CGSize {

        return CGSize(width: 120, height:120) 
    }


推荐答案

您需要在类声明中指定实现协议 UICollectionViewDelegateFlowLayout

You need to specify that you implement the protocol UICollectionViewDelegateFlowLayout in your class declaration.

class PhrasesCompactCollectionViewController:UICollectionViewController,UICollectionViewDelegateFlowLayout

这篇关于从未调用CollectionView sizeForItemAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 02:35