我知道那裏已經有問題了,但是我不理解他們,或者我只是不知道我在做什麼。所以,當我嘗試運行我的應用程序ViewView裏面的CollectionView
斷言失敗中我得到這個錯誤 - [UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] 終止應用程序由於未捕獲的異常「NSInternalInconsistencyException」,理由是:「不能出列類型的視圖:UICollectionElementKindCell與標識符DateCell - 必須註冊標識的筆尖或類或情節串連圖板」
連接原型細胞,我不明白爲什麼我得到這個或如何解決它。
我有我已經註冊
import Foundation
import UIKit
class CVCell: UICollectionViewCell {
@IBOutlet weak var myCellLabel: UILabel!
}
然後在這裏一個小區類,是我的viewController:
import UIKit
class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
private let reuseIdentifier = "DateCell"
override func viewDidLoad() {
initializeVars()
//moreDateInfo()
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return moreDateInfo()
}
// make a cell for each cell index path
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
// get a reference to our storyboard cell
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CVCell
// Use the outlet in our custom class to get a reference to the UILabel in the cell
cell.myCellLabel.text = String(startOfMonthDate)
if (startOfMonthDate == numOfDaysInThisMonth) {
startOfMonthDate = 1
} else {
startOfMonthDate++
}
//cell.backgroundColor = UIColor.yellowColor() // make cell more visible in our example project
cell.layer.borderColor = UIColor.blackColor().CGColor
cell.layer.borderWidth = 1
cell.layer.cornerRadius = 10
return cell
}
// MARK: - UICollectionViewDelegate protocol
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
// handle tap events
print("You selected cell #\(indexPath.item)!")
}
func collectionView(collectionView: UICollectionView, didHighlightItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell?.backgroundColor = UIColor.blackColor()
}
// change background color back when user releases touch
func collectionView(collectionView: UICollectionView, didUnhighlightItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell?.backgroundColor = UIColor.whiteColor()
}
並且最初可能需要註冊nib類: – Anny