보기 컨트롤러에서 두 개의 컬렉션보기를 사용하려고하는데 결과적으로이 오류 메시지가 나타납니다? 이 문제를 해결하기 위해 제가 누락 된 부분을 지적 해 주시겠습니까? 미리 감사드립니다. 아래보기 컨트롤러에서 "OtherViewController"라는 코드가 있습니다.UICollectionView가 non-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) -> 지능 {
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
}
}