【发布时间】:2017-06-18 16:43:37
【问题描述】:
在我的 iOS 应用程序中,我有一个 UICollectionView 控制器,其中包含以下代码:
var images = [UIImage]()
override func viewDidLoad() {
super.viewDidLoad()
loadImages()
// Register cell classes
}
func loadImages() {
images.append(UIImage(named: "ActivityTab")!)
self.collectionView?.reloadData()
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return images.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! EventCollectionViewCell
let image = images[indexPath.row]
cell.imageView.image = image
return cell
}
我有一个 UICollectionViewCell (EventCollectionViewCell),代码如下:
@IBOutlet weak var imageView: UIImageView!
override func prepareForReuse() {
super.prepareForReuse()
self.imageView.image = nil
}
我也将所有内容与故事板联系起来。这看起来应该可以工作,但我收到以下错误:
无法将 'UICollectionViewCell' (0x1092c04a8) 类型的值转换为 EventCollectionViewCell'
有谁知道错误是什么以及如何解决它。它只在我返回 images.count 时显示。
我正在使用 xcode 9,但已尝试使用 xcode 8,但错误仍然存在。任何帮助将不胜感激。 :)
【问题讨论】:
-
loadImages(){ is // Register cell classes}你在那里正确注册了EventCollectionViewCell吗?
标签: swift xcode uicollectionview uicollectionviewcell