未定义UICollectionViewFlowLayout的行为

时间:2015-04-26 06:04:45

标签: ios objective-c swift uicollectionview

我一直在尝试重新创建示例项目here

我已经创建并更新了Bridging-header文件,并正在使用我的ViewController.swift来使用这些库。

我的ViewController.swift:

代码

import UIKit

class ContinueViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {

override func viewDidLoad()
{


}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
    return 1;
}

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int
{
    return 4;
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
    //var cell = RGCollectionViewCell()

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("reuse", forIndexPath: indexPath) as! RGCollectionViewCell
    self.configureCell(cell, withIndexPath: indexPath)

    return cell;
}

func configureCell(cell: RGCollectionViewCell!, withIndexPath indexPath: NSIndexPath!)
{
    let subview = (cell.contentView .viewWithTag(99)) as UIView!
    subview.removeFromSuperview()

    switch (indexPath.section)
    {
    case 0:
        cell.imageView.image =  UIImage(named: "i1")
        cell.mainLabel.text = "Glaciers";
        break;
    case 1:
        cell.imageView.image =  UIImage(named: "i2")
        cell.mainLabel.text = "Parrots";
        break;
    case 2:
        cell.imageView.image =  UIImage(named: "i3")
        cell.mainLabel.text = "Whales";
        break;
    case 3:
        cell.imageView.image =  UIImage(named: "i4")
        cell.mainLabel.text = "Lake View";
        break;
    case 4:
        cell.imageView.image =  UIImage(named: "i5")
        break;
    default:
        break;
    }


}

}

我也创建了相同的故事板元素并将它们联系起来。

但是当我构建项目时,构建成功但是当它在iOS模拟器中打开时,它崩溃并且控制台窗口显示,

2015-04-26 11:20:45.699  the behavior of the UICollectionViewFlowLayout is not defined because:
2015-04-26 11:20:45.700 the item width must be less than the width of the UICollectionView minus the section insets left and right values.
 fatal error: unexpectedly found nil while unwrapping an Optional value

使用Debug Navigator指向该行

subview.removeFromSuperview()

突出显示EXC_BAD_INSTRUCTION(code=EXC_i386_INVOP, subcode=0x0)

0 个答案:

没有答案