2016-04-03 8 views
0

私はすでにそこに質問があることを知っていますが、私はそれらを理解していないか、私は何をしているのか分かりません。私は私のアプリ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() 
    } 

は私の絵コンテです:

答えて

1

であるべき:

let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CVCell 

は実際にあなたのCVCellクラスを登録しません。これを行うには、viewDidLoadregisterClass:forCellReuseIdentifier:を使用してください。また、ストーリーボード内のセルを選択し、右側にプロパティインスペクタで、再利用識別子「の下DataCell」 『を入力してください』。

0

うわー、私はスペルを持っていたがエラー.....これらのタイプミスを忘れることはありません。

private let reuseIdentifier = "DateCell" 

は、このライン "DataCell"

1

あなたのセル名が間違っている 『

DateCell』そして、あなたがする必要があるかもしれ(: "SelectCategoriesCell"、バンドル:ゼロ)、forCellWithReuseIdentifier:UINib(nibName reuseIdentifier)

以下self.collectionViewCategory.registerNibのようなペン先のクラス登録プロトタイプ細胞と私の絵コンテで

+0

、最初はnibクラスを登録する必要があります: – Anny

1

を、登録する必要はありませんストーリーボードはそれを処理します。

関連する問題