1

I am using UICollectionView and setting the size of the cell using the following method:

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        return CGSizeMake(collectionView.bounds.size.width, 313)
    }

Cell size is okay when the view is loaded. But, when orientation changes the cell size is not updated according to view width and height.

I tried to detect the device orientation and did it properly. When device orientation changes, the following method is called:

func rotated()
{
    self.shareLogCollectionView.reloadData()
}

But, I get the following error: fatal error: unexpectedly found nil while unwrapping an Optional value

So, how can I update the cell size and adjust according to the changes of device orientation? Kindly help!

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • 1
    'unexpectedly found nil while unwrapping an Optional value' is shown when an unwrapping object is nil. Please check whether shareLogCollectionView has the right outlet connected. – krishnanunni Apr 12 '16 at 05:41
  • Thanks a lot, you are right! I have somehow referenced the outlet improperly. – Seemanta Saha Apr 12 '16 at 05:54

1 Answers1

1

As @krishnanunni already mentioned,

Please check whether shareLogCollectionView has the right outlet connected. This is a very common mistake.

also for rotate you can use viewWillTransitionToSize

Please check.

Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256