【发布时间】:2015-08-24 16:50:06
【问题描述】:
我做了一个基于 xib 的快速项目,并在我的视图控制器中创建了一个集合视图,添加了它的委托,使用默认的 collectionViewCell 一切都很好
问题是当我创建自定义单元格时 我在 xib 中正确添加了重用标识符
然后在视图控制器的确实加载中添加这些行
collectionViewCarType.delegate = self;
collectionViewCarType.dataSource = self;
collectionViewCarType.registerClass(MainScreenCollectionViewCell.self, forCellWithReuseIdentifier: "MainScreenCollectionViewCell");
我添加了断点,这里没有崩溃
然后在:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
我添加了这些行:
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("MainScreenCollectionViewCell", forIndexPath: indexPath) as! MainScreenCollectionViewCell
cell.backgroundColor = UIColor.redColor()
cell.labelOfTime.text = "10 mins"
cell.labelOfType.text = "Mini"
return cell
应用程序在到达cell.labelOfTime.text 时崩溃
当我删除标签 2 行时,它可以很好地为单元格着色
我也使 2 标签和集合视图变得强大,但它也崩溃了
我删除了 xib 并使用不同的名称创建它并尝试使用它,但我也遇到了同样的错误
我是 swift 新手,我不知道我还能做什么
【问题讨论】:
-
请编辑您的问题以包含崩溃错误消息。
-
发布 MainScreenCollectionViewCell 的代码
标签: ios iphone swift uicollectionview