18

I am using UICollectionView but following method not found:

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

please suggest me it's replacement.

beryllium
  • 29,669
  • 15
  • 106
  • 125
Vikram Biwal
  • 2,618
  • 1
  • 25
  • 36

2 Answers2

82

For me sizeForItemAt wasn't called because in Swift 3 you need to explicitly set your class to implement the UICollectionViewDelegateFlowLayout protocol

Roland Keesom
  • 8,180
  • 5
  • 45
  • 52
  • 3
    You saved my lot time, as I am not very familiar with CollectionView but I have to use it for one of my apps. +1 for your very important instruction – g212gs Feb 10 '17 at 12:05
  • 1
    Especially useful, when you just migrated an existing project to Swift 3 and wondered why your collection views are suddenly broken. – retendo Apr 27 '17 at 10:20
54

This is the new syntax for that:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

}  
Nirav D
  • 71,513
  • 12
  • 161
  • 183
JFAP
  • 3,617
  • 1
  • 24
  • 25