Это мой View Controller, в котором я установил свой collectionView и его методы.
class HomeScreenViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
@IBOutlet weak var collectionViewOne: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionViewOne.register(UINib(nibName: "recomendedcell1", bundle: nil), forCellWithReuseIdentifier: "cell1")
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = Bundle.main.loadNibNamed("recommendedcell1", owner: self, options: nil)?.first as! CustomCellOneCollectionViewCell
return cell
}
Это мой пользовательский файл ячейки
class CustomCellOneCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
Я также использовал приведенный ниже код для объявления ячейки.
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell1", for: indexPath) as! CustomCellOneCollectionViewCell
Я проверил все соединения, дважды проверил имена идентификаторов.Контроллер моего представления является частью контроллера панели вкладок.