我有一个导航选项卡栏,每个选项卡包含一个数组的图片,请参阅下图。我的问题是。为什么这个枚举只能看到顶级案例“男士”,它不会转向女性,艺术和保存。我试图删除案例男士,那么它只能看到案例“女人”,无论是在顶部,这只是cellForItemAtIndexPath可以看到的东西。一切都已经连接我试图让他们一个一个看看他们是否正在工作,他们都在工作。但它只能看到最上面的东西。我不明白什么遗漏在了这里,为什么枚举只能读取顶部的情况?
class StreamDetailController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate{
private enum Tabs: Int {
case mens
case women
case arts
case saved
}
var menImage = [Men]()
var artsImage = [Arts]()
var womenImage = [Women]()
var savedImage = [SavedPhotos]()
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
guard let tab = Tabs(rawValue: section) else {
assertionFailure()
return section
}
switch tab {
case .mens:
return menImage.count
case .women:
return womenImage.count
case .arts:
return artsImage.count
case .saved:
return savedImage.count
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let tab = Tabs(rawValue: indexPath.section) else {
assertionFailure()
return UICollectionViewCell()
}
switch tab {
case .mens:
let cell = extraCells.dequeueReusableCell(withReuseIdentifier: "Cells", for: indexPath) as! ExtraViewCell
let men = menImage[indexPath.item]
cell.boxImage.image = men.image
return cell
case .women:
let cell = extraCells.dequeueReusableCell(withReuseIdentifier: "Cells", for: indexPath) as! ExtraViewCell
let women = womenImage[indexPath.item]
cell.boxImage.image = women.image
return cell
case .arts:
let cell = extraCells.dequeueReusableCell(withReuseIdentifier: "Cells", for: indexPath) as! ExtraViewCell
let art = artsImage[indexPath.item]
cell.boxImage.image = art.image
return cell
case .saved:
let cell = extraCells.dequeueReusableCell(withReuseIdentifier: "Cells", for: indexPath) as! ExtraViewCell
let save = savedImage[indexPath.item]
cell.boxImage.image = save.image
return cell
}
}
什么是分配后'tab'的价值? – Alexander
对不起亚历山大,我不明白你的意思。 – Cookingcodes
'guard let tab = ...'和'switch tab'之前'tab变量的值是什么? – Alexander