I am trying to use two collection views inside of a view controller and I get this error message as a result? Can you point out what i am missing to correct this issue? Thanks in advance.. Below is my code in the view controller named "OtherViewController".
class 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)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: 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 label to to see if cellB will appear in collection view
return cellB
}
}