为什么从未调用sizeForItemAtIndexPath?

时间:2016-02-13 18:18:07

标签: swift2 uicollectionviewlayout

在我的自定义视图控制器中定义如下:

class Wall : UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, WallLayoutDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        let layout = WallLayout()
        layout.delegate = self


        let collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
        collectionView.registerClass(WallCell.self, forCellWithReuseIdentifier: Wall.reuseIdentifier)
        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.backgroundColor = UIColor.blackColor()

        self.view.addSubview(collectionView)

        self.collectionView = collectionView
   }
   // CODE

   func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
      return CGSizeMake(50, 100)
   }

}    

永远不会调用函数sizeForItemAtIndexPath。它是怎么来的?

1 个答案:

答案 0 :(得分:2)

我发现这是因为当我使用UICollectionViewDelegateFlowLayout并且无法通过集合视图推断时,布局由我决定。