私はすでにそこに質問があることを知っていますが、私はそれらを理解していないか、私は何をしているのか分かりません。私は私のアプリCollectionView inside ViewController
アサーション失敗実行しようとするので、私はこのエラーを取得しています - [UICollectionView _dequeueReusableViewOfKindを:withIdentifier:forIndexPath:viewCategory:] がキャッチされない例外により「NSInternalInconsistencyException」、理由にアプリを終了:「できませんでした種類のデキュービュー:識別子DateCellとUICollectionElementKindCell -
「識別子のためのペン先やクラスを登録したり、ストーリーボードでプロトタイプセルを接続する必要があり、私はこのまたはその解決方法を取得していますなぜ私は理解していません。
私は
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