Seemanta Saha
Seemanta Saha

Reputation: 86

How to change UiCollectionView cell size when device orientation changes?

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!

Upvotes: 1

Views: 1285

Answers (1)

Sazzad Hissain Khan
Sazzad Hissain Khan

Reputation: 40136

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.

Upvotes: 1

Related Questions