【问题标题】:collection view's delegate conforms to another protocol集合视图的委托符合另一个协议
【发布时间】:2016-03-24 20:58:21
【问题描述】:

我正在使用CollectionViewWaterfallLayout。在“如何使用”部分,它说

您的集合视图的委托必须符合 CollectionViewWaterfallLayoutDelegate 协议并实现 required 方法,您需要做的就是返回原始大小 项目:

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

我应该在这里做什么?如何让collection view的delegate符合CollectionViewWaterfallLayoutDelegate协议?

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    在你的主视图控制器中添加CollectionViewWaterfallLayoutDelegate,这样它就会像

    class SearchPhotosViewController: UIViewController, CollectionViewWaterfallLayoutDelegate,UICollectionViewDataSource { 
    
    //inside this call the delegate method to return the size of the item
    
        func collectionView(collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
            return CGSizeMake(300, 300)//return the CGSize for the item you want
        }
    }
    

    【讨论】:

      【解决方案2】:

      在声明类时,您是否编写了符合 UICollectionViewDelegae 的代码。下面的示例代码:

      class myViewController : UIViewController, UICollectionViewDelegate {
      
      ...
      
      }
      

      【讨论】:

      • 我试过class SearchPhotosViewController: UIViewController, UICollectionViewDataSource, CollectionViewWaterfallLayoutDelegate, UISearchBarDelegate, UICollectionViewDelegateFlowLayout {}但没用。报错“Type SearchPhotosViewController不符合协议CollectionViewWaterfall LayoutDelegate”
      • 您是否实现了 CollectionViewWaterfallLayoutDelegate 中提到的所有必需方法?
      猜你喜欢
      • 1970-01-01
      • 2018-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多