UICollectionView Auto Resizing Results in Error

I'm working on a toy app to investigate something else involving UICollectionView. Because I need to (just accept the premise and move on) I'm trying to display text in the cells using auto layout. For some reason after a certain point, the application starts failing with EXC_BAD_ACCESS(code=2, address=0x7fff532ebfd0). I can't figure out why.

I'm not doing anything fancy. Here's the estimated size code.

    if let cvl = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
        cvl.estimatedItemSize = CGSize(width: 40, height: 30)
    }

Here's the datasource method.

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

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("reuse", forIndexPath: indexPath) as! LabelCell

    let string = stCrispensDaySpeech[indexPath.row]

    cell.label.text = string
    cell.backgroundColor = UIColor.grayColor()

    return cell

}

You can get the whole project at furry-waddle tag.

Answers


I saw your code and I found the problem:

The problem is when "," character appear, because the width of cell (minimum = 40)

Just change it your code like this:

    if let cvl = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
        cvl.estimatedItemSize = CGSize(width: 10, height: 30)
    }

Need Your Help

Convert ColorConvertedBitmap to byte array in C#

c# wpf bitmap

I need to get the byte array from my ColorConvertedBitmap representing the bitmap. I was trying to use CopyPixels method but with no success.