Когда я объявляю представление коллекции с областью действия, оно не регистрирует класс ячейки
lazy var flowLayout:UICollectionViewFlowLayout = {
let f = UICollectionViewFlowLayout()
f.scrollDirection = .horizontal
f.itemSize = CGSize(width: 100, height: 100)
f.minimumInteritemSpacing = CGFloat.greatestFiniteMagnitude
f.minimumLineSpacing = 5
return f
}()
lazy var collection: UICollectionView = {
let cv = UICollectionView(frame: CGRect.zero, collectionViewLayout: self.flowLayout)
cv.translatesAutoresizingMaskIntoConstraints = false
cv.showsVerticalScrollIndicator = false
cv.showsHorizontalScrollIndicator = false
cv.dataSource = self
cv.delegate = self
cv.register(PreviewFilmsPosterCell.self, forCellWithReuseIdentifier: cellId)
cv.backgroundColor = .black
return cv
}()
Выдает эту ошибку:
Завершение приложения из-за необработанного исключения
NSInternalInconsistencyException, причина: попытка зарегистрировать
класс ячейки, который не является подклассом UICollectionViewCell
что такое правильное решение?
обновление
но если я заявляю, что так, то это работает
override func viewDidLoad() {
collectionview = UICollectionView(frame: CGRect.zero, collectionViewLayout: flowLayout)
collectionview.translatesAutoresizingMaskIntoConstraints = false
collectionview.dataSource = self
collectionview.delegate = self
collectionview.register(PreviewFilmsPosterCell.self, forCellWithReuseIdentifier: cellId)
collectionview.showsVerticalScrollIndicator = false
collectionview.showsHorizontalScrollIndicator = false
collectionview.backgroundColor = .black
}
my PreviewFilmsPosterCell Class
class PreviewFilmsPosterCell: UICollectionViewCell {
let profileImageButton: UIButton = {
let button = UIButton()
button.layer.cornerRadius = 50
button.clipsToBounds = true
button.setImage(UIImage(named: "profile_batman"), for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
return button
}()
override init(frame: CGRect) {
super.init(frame: frame)
addViews()
}
func addViews(){
backgroundColor = UIColor.clear
addSubview(profileImageButton)
profileImageButton.heightAnchor.constraint(equalToConstant: 100).isActive = true
profileImageButton.widthAnchor.constraint(equalToConstant: 100).isActive = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}