【发布时间】:2024-01-05 01:12:01
【问题描述】:
我有一个UICollectionView,其中有一个带有UIImageView 的自定义单元格,还有一个带有插座的自定义类
class theCell: UICollectionViewCell {
@IBOutlet var theImage:UIImageView!
}
我有一个UIImage 数组(只有一个常量图像)。图片在主包中。
var tempImages = [UIImage(named: "placeholder.png" )]
委托方法
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return tempImages.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = self.collectionView?.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! theCell
//Unexpectadly found nil
cell.theImage.image = tempImages[indexPath.row]
return cell
}
【问题讨论】:
-
我不知道你说的返回 nil 是什么意思?
-
@AndriusSteponavičius 致命错误:在展开可选值时意外发现 nil
-
如果是png就不需要放.png
-
你设置 yourcollection.delegate = self 和 yourcollection.dataSource = self 了吗?
-
@Totka 我添加了这些,但仍然有同样的错误
标签: ios iphone swift uicollectionview swift2