János
János

Reputation: 35112

Crash when loading UICollectionView in, why?

There is no error log just this what I see.

I have a dynamic prototype UICollectionViewCell, and loading in here:

override func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! {

    var cell: LeftMenuCollectionViewCell

cell = collectionView.dequeueReusableCellWithReuseIdentifier("xxx", forIndexPath: indexPath) as LeftMenuCollectionViewCell // <- at this line something goes wrong

    return cell
}

I am registering class before:

self.collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "xxx")

Using iOS 8 beta 5 now

enter image description here

Upvotes: 0

Views: 1924

Answers (3)

J&#225;nos
J&#225;nos

Reputation: 35112

Agree with the two solution below, I registered cell incorrectly, but afterward I found an other issue, cell's outlets become nil. And the solution for that was to remove whole registration, if UICollectionViewController was created via Interface Builder.

Upvotes: 2

Anil Varghese
Anil Varghese

Reputation: 42977

You have registered UICollectionViewCell instead of your own cell class LeftMenuCollectionViewCell. So that the casting of

UICollectionviewCell as LeftMenuCollectionViewCell 

is breaking and causing the crash. To fix this register the proper class

self.collectionView.registerClass(LeftMenuCollectionViewCell.self, forCellWithReuseIdentifier: "xxx")

Upvotes: 2

wottle
wottle

Reputation: 13630

You have registered the cell incorrectly. Try this:

self.collectionView.registerClass(LeftMenuCollectionViewCell.self, forCellWithReuseIdentifier: "xxx")

Upvotes: 1

Related Questions