In meinem Sichtcontroller möchte ich zwei Sammlungsansichten haben. Nachdem ich das versucht habe, bekam ich einen Sigabrt-Fehler und meine App stürzt ab. Ich prognostiziere, dass das Problem liegt, weil ich die Datenquelle dieser Sammlungsansichten selbst zuweisen. Ich falsch sein kann, hier ist mein Code:Zwei Sammlungsansichten mit verschiedenen Wiederverwendungszellen in einer Ansicht Controller
Im Hinblick tat Last, i die Datenquelle der Sammlung Ansichten gesetzt:
@IBOutlet var hashtagCollectionView: UICollectionView!
@IBOutlet var createCollectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
createCollectionView.dataSource = self
hashtagCollectionView.dataSource = self
}
Dann habe ich eine Erweiterung für den UICollectionViewDataSource erstellen
extension CategoryViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
var returnValue = 0
if collectionView == hashtagCollectionView {
// Return number of hashtags
returnValue = hashtags.count
}
if collectionView == createCollectionView {
// I only want 3 cells in the create collection view
returnValue = 3
}
return returnValue
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
var return_cell: UICollectionViewCell
// Place content into hashtag cells
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "hashtagCell", for: indexPath) as! TrendingTagsCollectionViewCell
cell.hashtagText = hashtags[indexPath.row]
// Place content in creators cell
let createCell = collectionView.dequeueReusableCell(withReuseIdentifier: "createCell", for: indexPath) as! CreateCollectionViewCell
createCell.text = creators[indexPath.row]
createCell.image = creatorImages[indexPath.row]
// Is this the right logic?
if collectionView == hashtagCollectionView {
return_cell = cell
} else {
return_cell = createCell
}
return return_cell
}
}
Danke testen sollen, funktioniert dies! – vApp