我在我的Collection视图电池连接到一个自定义的,但它崩溃,我已经写了自定义单元格的类名,创造了一流的,但是当我铸造dequeueReusableCell崩溃Collection视图细胞崩溃
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! PlatformCollectionViewCell
if let platformCell = cell as? PlatformCollectionViewCell {
platformCell.backgroundColor = UIColor.blue
platformCell.titleLabel.text = "Hola"
return cell
}
cell.backgroundColor = UIColor.green
return cell
}
唯一可能的错误,我发现是当它给我的错误是说像
无法投类型的值“UICollectionViewCell”(0x1b12070b0)为“Quote.PlatformCollectionViewCell”(0x1000bba00)。 2017-04-02 13:24:32.711435 + 0200引用[1219:351279]无法将类型'UICollectionViewCell'(0x1b12070b0)的值转换为'Quote.PlatformCollectionViewCell'(0x1000bba00)。
我不知道是否可以在最后一行显示“NameOfTheProject.Class”。我觉得应该说只是类,但我不知道如何解决这个问题,在这种情况下是错误
类PlatformCollectionViewCell是这个
//
import UIKit
class PlatformCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var titleLabel: UILabel!
}
什么是PlatformCollectionViewCell?你能表演那堂课吗?它应该是UICollectionViewCell的子类 –
你可以分享如何注册你的细胞吗? 'reuseIdentifier' –
我已经更新了问题 –