我在我的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' –
我已經更新了問題 –