Ios Swift-无法将类型为UICollectionElementKindCell的视图出列

Ios Swift-无法将类型为UICollectionElementKindCell的视图出列,ios,swift,cocoapods,jtapplecalendar,Ios,Swift,Cocoapods,Jtapplecalendar,我在尝试加载项目时收到此错误消息 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法将具有标识符CustomCell的UICollectionElementKindCell类型的视图出列-必须为标识符注册nib或类,或连接情节提要中的原型单元格” 我的代码是: extension ViewController: JTAppleCalendarViewDelegate, JTAppleCalendarViewDataSource {

我在尝试加载项目时收到此错误消息

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法将具有标识符CustomCell的UICollectionElementKindCell类型的视图出列-必须为标识符注册nib或类,或连接情节提要中的原型单元格”

我的代码是:

extension ViewController: JTAppleCalendarViewDelegate, JTAppleCalendarViewDataSource {
    func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
        formatter.dateFormat = "yyyy MM dd"
        formatter.timeZone = Calendar.current.timeZone
        formatter.locale = Calendar.current.locale

        let startDate = formatter.date(from: "2017 01 01")!
        let endDate = formatter.date(from: "2017 12 31")!

        let parameters = ConfigurationParameters(startDate: startDate, endDate: endDate)
        return parameters
    }

    func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
        let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CustomCell
        cell.dateLabel.text = cellState.text
        return cell
    }
}
请帮我调试这个问题。多谢各位

编辑:我已经添加了单元格的标识符,但仍然存在错误


这是因为您尚未将xib注册到
UICollectionView
。如果您使用的是来自Xib的
UICollectionViewCell
,则必须先注册它

In viewDidLoad: 
写下来:

if let xib = NSNib.init(nibNamed: "TemplateNBgCollectionItem", bundle: nil) {
   self.collectionView.register(xib, forItemWithIdentifier: NSUserInterfaceItemIdentifier(rawValue: "cvItem"))  
}
  • 如果您在storyboard notXIB中使用单元格,则需要如下设置reuseIDentifier

  • 如果对单元格使用单独的XIB,则需要在
    ViewDidLoad

    register(UINib(nibName:“nibName”,bundle:nil),forCellWithReuseIdentifier:“reuseIdentifier”)


  • viewDidLoad
    方法中: 必须向collectionView对象注册自定义单元格类/xib名称

    如果您只有类自定义类,那么您可以通过以下方式注册(无xib文件)

    如果您同时拥有类和xib文件,那么您可以通过这种方式注册

    collectionView.register(UINib(nibName: "CustomCell", bundle: nil), forCellWithReuseIdentifier: "cellId")
    

    从您粘贴的代码片段中,我看不到您在想要退出/使用单元格之前注册了它。在使用前需要注册单元格,如错误所述

    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "DefaultCell")
    
    如需快速参考,请参阅下面的帖子-


    发布屏幕截图后编辑(如果适合您,请接受此答案^ u^)

    从屏幕截图中,您正在使用自定义单元格类“CustomCell”,设置正确的标识符后,请确保在右侧面板的标识检查器中将正确的类名设置为CustomCell。请参阅下面的屏幕截图。
    这个问题有很多可能。如果您有
    集合视图
    的自定义类,则应在
    标识检查器
    中设置该类。并且它必须是
    UICollectionViewCell
    的子类。您必须在
    cellforitem
    委托方法中实例化该子类,并使用必须在
    属性检查器中设置的适当的
    可重用标识符
    。在您的屏幕截图中,似乎
    苹果日历视图
    是您的收藏视图。如果它是第三方库,那么请确保它允许您对自定义单元格进行消隐!并确保它是
    UICollectionView
    的子类

    就我而言 我正在使用类为的自定义单元格创建集合视图


    这是我的自定义收藏视图类代码

    import UIKit
    class Auction_CollectionCell: UICollectionViewCell {
    
    @IBOutlet weak var Productimage: UIImageView!
    @IBOutlet weak var name: UILabel!
    @IBOutlet weak var bid: UILabel!
    @IBOutlet weak var progress: UIProgressView!
    @IBOutlet weak var day: UILabel!
    @IBOutlet weak var hours: UILabel!
    @IBOutlet weak var mins: UILabel!
    @IBOutlet weak var secs: UILabel!
    @IBOutlet weak var lblday: UILabel!
    @IBOutlet weak var lblhours: UILabel!
    @IBOutlet weak var lblmin: UILabel!
    @IBOutlet weak var lblsecs: UILabel!
    @IBOutlet weak var MainView: UIView!
    
       override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        }
    }
    
    通过CTRL+Drag将故事板中的所有视图连接到自定义类,并将创建@IBOutlet。
    我这样调用我的自定义类

    self.AuctionList=NSArray与NSDictionary内容

    祝你玩得开心,好运。
    请随意编辑我的答案

    我的答案也有同样的问题。环顾四周后,我意识到我有一个小写字母“p”,而它应该是大写字母“p”,我用它作为标识符


    单击序列图像板上的collectionView单元,打开右侧面板。检查属性检查器和集合可重用视图、标识符名称,但也检查标识检查器、自定义类名。

    您是否在序列图像板的collectionviewcell中添加了CustomCell reuseIdentifier?可能与@NishantbIndi重复这些答案都不适用于我:/what's class of your cell?您是否已在身份检查器中设置了类?此问题是否已解决?很抱歉,我对此非常陌生。当我尝试你的建议时,我得到了以下错误-使用未解析标识符'collectionView',哦,这是因为我将collectionView作为伪文本。您需要做的是:创建一个名为collectionView的UICollectionView的IBOutlet。那么你对我很好,你能告诉我我到底需要做什么,我需要把它放在哪里吗。抱歉,这是我第一次做所有这些,转到IB上的控制器。Ctrl+拖动到您的this controller类。然后,当它提示时,使用name:collectionview更新后我会看到您的屏幕截图,只是在连接IBOutlet时要小心,并确保名称与您的xib匹配。或者您可以将其重新连接到双重检查。Good LuckI使用了这一点,但我对line let cell=calendar.dequeueReusableJTAppleDayCellView(使用reuseidentifier:“JTCustomCell”,for:indexPath)仍然有问题!JTCustomCell
    import UIKit
    class Auction_CollectionCell: UICollectionViewCell {
    
    @IBOutlet weak var Productimage: UIImageView!
    @IBOutlet weak var name: UILabel!
    @IBOutlet weak var bid: UILabel!
    @IBOutlet weak var progress: UIProgressView!
    @IBOutlet weak var day: UILabel!
    @IBOutlet weak var hours: UILabel!
    @IBOutlet weak var mins: UILabel!
    @IBOutlet weak var secs: UILabel!
    @IBOutlet weak var lblday: UILabel!
    @IBOutlet weak var lblhours: UILabel!
    @IBOutlet weak var lblmin: UILabel!
    @IBOutlet weak var lblsecs: UILabel!
    @IBOutlet weak var MainView: UIView!
    
       override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        }
    }
    
    func collectionView(_ collectionView: UICollectionView,
                        numberOfItemsInSection section: Int) -> Int {
        return self.AuctionList.count
    }
    func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    
     let cell : Auction_CollectionCell = (collectionView.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath) as? Auction_CollectionCell)!
    
        cell.lblday.text = "Day"
        cell.lblhours.text = "Hours"
        cell.lblmin.text = "Minutes"
        cell.lblsecs.text = "Secs"
    
        cell.MainView.layer.cornerRadius = 5
        cell.MainView.backgroundColor = UIColor.white
        cell.MainView.layer.borderWidth = 0.5
        cell.MainView.layer.borderColor = UIColor.gray.cgColor
    
    
        return cell
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
     var width = CGFloat(0)
     var height = CGFloat(0)
     if (UIDevice.current.userInterfaceIdiom == .pad){
       width = CGFloat((self.view.bounds.size.width / 4.0) - 15)
       height = CGFloat(246.0)
     }else{
       width = CGFloat((self.view.bounds.size.width / 2.0) - 15)
       height = CGFloat(246.0)
    }
    
       print("Resize Image \(width) \(height)")
       return CGSize(width: width, height: height)
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    if let dic = AuctionList[indexPath.row] as? NSDictionary{
        Product.product_id = "\((dic["product_id"])!)"
        Product.product_image = "\((dic["image"])!)"
        Product.auction_id = "\((dic["auction_id"])!)"
        performSegue(withIdentifier: "auctionProductDetails", sender: self)
      }      
    }