-1

I am building an app where I use a UICollectionView, but when I register my Cell, It gives me the error,

Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeeca55ff8)

I have no idea what this means, can someone help me, please? I'm sorry if I didn't provide enough code, please ask me if u need more. Here is my code:

import UIKit

class ThingsToDoCollectionView: UICollectionView {

override func register(_ cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String) {

    register(UICollectionView.self, forCellWithReuseIdentifier: "ThingsToDoCollectionViewCell")

    }


}

EDIT: here is the code for my ThingsToDoUICollectionViewCell

import UIKit

class ThingsToDoCollectionViewCell: UICollectionViewCell {


@IBOutlet weak var GIDThumbnail: UIImageView!
@IBOutlet weak var GIDTitle: UILabel!
@IBOutlet weak var GIDDueDate: UILabel!


}
  • You aren't registering your cell class, you are registering the base UICollectionView class - check your code - you should use the arguments that you function accepts. – Paulw11 Jun 08 '19 at 20:42

1 Answers1

0

You should register the cell in the viewDidLoad method of your UIViewController which has a UICollectionView

self.collectionView.register(UINib(nibName: "YourCellXIBFileName", bundle: nil), forCellWithReuseIdentifier: "YourCellReuseIdentifier")
kirami
  • 273
  • 1
  • 4
  • I tried that, and not only does it solve the problem, it also gives me a new error 'Thread 1: signal SIGABRT' stating that 'could not dequeue a view of kind: UICollectionElementKindCell with identifier ThingsToDoCollectionViewCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' –  Jun 09 '19 at 00:08
  • Hımm can you please share your ThingsToDoCollectionViewCell ? The error said that your cell is not a UICollectionViewCell, can you check it – kirami Jun 09 '19 at 06:17
  • Have you got a XIB file of your cell ? – kirami Jun 09 '19 at 06:21
  • ok, I shared my ThingsToDoCollectionView, does the main storyboard count as a XIB file for my cell? –  Jun 09 '19 at 15:38
  • if your cell on the collection view in the main storyboard, no need register – kirami Jun 09 '19 at 16:56
  • I tried deleting my register, but it gives me the same Thread 1: signal SIGABRT error –  Jun 09 '19 at 19:05