Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exc_arithmetic error with simulator only, assigning UICollectionView flowlayout

Im trying to assign a UICollectionViewFlowLayout to a UICollectionView and it runs fine on a physical device but simulators break, with a signal:

EXC_ARITHMETIC(code=EXC_i386_DIV, subcode=0x0)

This only happens on a simulator, it is my understanding that this is usually a division by 0 error, but I dont see how thats possible for my implementation

Code:

let flowLayout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()

flowLayout.itemSize =  CGSizeMake(self.view.bounds.width * 0.67,
                                      self.collectionView!.frame.height - 10)

flowLayout.scrollDirection = UICollectionViewScrollDirection.Horizontal

self.collectionView!.collectionViewLayout = flowLayout

Furthermore, i get the signal at this line: self.collectionView!.collectionViewLayout = flowLayout

and the view bounds are : WIDTH: 277.38 HEIGHT: 75.0

Any help, or alternatives would be greatly appreciated!

like image 834
justin shores Avatar asked Aug 30 '15 23:08

justin shores


2 Answers

I got the exact same issue on a old code I am working on and it appears that I was calling this code from a wrong method. I moved it in more appropriate place, viewDidLoad or init and it works.

like image 45
Ganzolo Avatar answered Oct 19 '22 02:10

Ganzolo


Helped to call

reloadData

before

setCollectionViewLayout

like image 132
Nick Rostov Avatar answered Oct 19 '22 03:10

Nick Rostov