在为集合视图中的集合视图提供数据时,我遇到了问题。我想我做得不好。我从第一个集合视图的数据源延迟中获取indexpath.item,以在第一个集合视图的单元格内的集合视图中提供数据。索引在第一个集合视图的第三个单元格中都可以,但是文本将重置为星期一。有什么办法解决吗?
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: StickersCell.reuseIdentifier, for: indexPath) as! StickersCell
switch indexPath.item {
case 0:
indexDan = 0
print(indexPath.item)
case 1:
indexDan = 1
print(indexPath.item)
case 2:
indexDan = 2
print(indexPath.item)
case 3:
indexDan = 3
print(indexPath.item)
case 4:
indexDan = 4
print(indexPath.item)
case 5:
indexDan = 5
print(indexPath.item)
default:
indexDan = 6
print(indexPath.item)
}
和第二个集合视图,我要在其中显示一些标签:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! kartica
if indexDan == 0 {
cell.labelMenu.text = "Monday"
}else if indexDan == 1 {
cell.labelMenu.text = "Tuesday"
}else if indexDan == 2 {
cell.labelMenu.text = "Wednesday"
}else if indexDan == 3 {
cell.labelMenu.text = "Thursday"
}else if indexDan == 4 {
cell.labelMenu.text = "Friday"
}
}
有什么想法吗?谢谢