ビューコントローラ内で2つのコレクションビューを使用しようとしていますが、このエラーメッセージが表示されます。あなたはこの問題を解決するために私が見逃していることを指摘できますか?事前にありがとうございます.. 以下は "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)
}
FUNCの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"
// cellBがコレクションビューに表示されるかどうかを見るにはradomのラベル
return cellB
}
}