Я попытался сделать то, что, как мне кажется, все остальные вопросы, но я все еще получаю ошибку. Может быть, мне не хватает чего-то очевидного, но я просмотрел документацию и все, что вам кажется, вам нужен макет для инициализации.UICollectionView должен быть инициализирован с параметром макета без нуля, даже после инициализации в ViewDidLoad
let flowLayout = UICollectionViewFlowLayout()
flowLayout.scrollDirection = .vertical
collectionView = UICollectionView(frame: view.frame, collectionViewLayout: flowLayout)
collectionView?.delegate = self
collectionView?.dataSource = self
collectionView?.register(InterestCollectionViewCell.self, forCellWithReuseIdentifier: interestReuseIdentifier)
view.addSubview(collectionView!)
Коллекция Просмотр Делегат Метод
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return interests.count
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let vc = collectionView.dequeueReusableCell(withReuseIdentifier: interestReuseIdentifier, for: indexPath) as! InterestCollectionViewCell
vc.interestLabel.text = interests[indexPath.row].rawValue as String
return vc
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.size.width, height: 45)
}
показать свой метод просмотра делегатов –
Кажется, у вас есть проблема с делегатом. Обновите свой делегат с помощью этого UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout – Joe
Отсутствует размер элемента макета из вашего кода .... layout.itemSize = CGSize (ширина: 100, высота: 100) – Joe