我知道那里已经有问题了,但是我不理解他们,或者我只是不知道我在做什么。所以,当我尝试运行我的应用程序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