草庐IT

ios - CollectionView sizeForItemAtIndexPath 从未调用过

coder 2023-07-24 原文

这让我发疯!我有一个 UICollectionViewController,如下所示:

class PhrasesCompactCollectionViewController: UICollectionViewController

正在调用 numberOfSections 和 cellForItemAt,但从未调用 sizeForItemAtIndexPath。我在其他地方使用完全相同的代码并且它正确触发。我正在使用 Xcode 8 Beta 6。

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

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

最佳答案

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

类 PhrasesCompactCollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout

关于ios - CollectionView sizeForItemAtIndexPath 从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39107482/

有关ios - CollectionView sizeForItemAtIndexPath 从未调用过的更多相关文章

随机推荐