Я пытаюсь использовать два представления коллекции внутри контроллера представления, и я получаю это сообщение об ошибке в результате? Можете ли вы указать, что мне не хватает, чтобы исправить эту проблему? Спасибо заранее. Ниже мой код в контроллере представления с именем «OtherViewController».UICollectionView должен быть инициализирован параметром макета не-nil '
класс OtherViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
//1. CREATE A VARIABLE FOR YELLOW ARRAY SO THAT I CAN DEFINE A STRING
var exploreArray = [String]()
var exploreHeader = [String]()
var yellowImages = [String]()
var explorecategories = [String]()
@IBOutlet weak var mycollectionView: UICollectionView!
var collectionViewA = UICollectionView()
let collectionViewB = UICollectionView()
let collectionViewAIdentifier = "yellowCell"
let collectionViewBIdentifier = "yellowCell2"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
collectionViewA.delegate = self
collectionViewB.delegate = self
collectionViewA.dataSource = self
collectionViewB.dataSource = self
self.view.addSubview(collectionViewA)
self.view.addSubview(collectionViewB)
}
функ CollectionView (_ CollectionView: UICollectionView, numberOfItemsInSection раздел: Int) -> Int {
if collectionView == self.collectionViewA {
return exploreArray.count }
return 1 // Replace with count of your data for collectionViewB
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView == self.collectionViewA{
let cellA = collectionView.dequeueReusableCell(withReuseIdentifier: "yellowCell", for: indexPath) as! yellowCell
// Set up cell
//DISPLAY TITLE LABEL
cellA.yLabel.text = exploreHeader[indexPath.row]
//DISPLAY IMAGES
cellA.yellowImages.image = UIImage(named:yellowImages [indexPath.row])
//DISPLAY DESCRIPTION
cellA.yellowTextField.text = exploreArray [indexPath.row]
return cellA
}
else {
let cellB = collectionView.dequeueReusableCell(withReuseIdentifier: "yellowCell2", for: indexPath) as! yellowCell2
cellB.labe2.text = "Dolphin"
// just radom, чтобы увидеть, появится ли CellB в виде коллекции
return cellB
}
}