Stéphane de Luca
Stéphane de Luca

Reputation: 13583

Why is sizeForItemAtIndexPath never called?

In my custom view controller defined as follows:

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)
   }

}    

The function sizeForItemAtIndexPath is never called. How it comes?

Upvotes: 0

Views: 2426

Answers (1)

Stéphane de Luca
Stéphane de Luca

Reputation: 13583

I found that it is because the layout is up to me when I use UICollectionViewDelegateFlowLayout and cannot be deduced by the collection view.

Upvotes: 2

Related Questions