How to set UICollectionViewDelegateFlowLayout?

前端 未结 3 1765
深忆病人
深忆病人 2020-12-14 05:14

A UIViewController maintains a reference to a UICollectionView. The controller should modify the built-in flow layout using the UICollectionViewDelegateFlowLayout.

I

3条回答
  •  死守一世寂寞
    2020-12-14 05:49

    My two cents for macOS Mojave - Swift

    (I've fallen here searching for NSCollectionView... I do know question was about UICollectionView..)

    All said above (specifying delegate implies cell size, too) is correct for macOS, too.

    NOTE: If You write:

    class MyViewController:
        NSCollectionViewDelegate,
        NSCollectionViewDataSource,
        **NSCollectionViewDelegateFlowLayout** 
    {
    

    the method:

    func collectionView(_ collectionView: NSCollectionView, 
                          layout collectionViewLayout: NSCollectionViewLayout, 
                   sizeForItemAt indexPath: IndexPath) -> NSSize
    

    will be called.

    If removed, no delegate method will be called. (as class does not obey to the protocol).

提交回复
热议问题