我有一个集合视图,打开应用程序打开单元格时我需要两个不同的单元格,按下按钮打开另一个单元格感谢帮助
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if (indexPath.item % 2 == 0) {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TOWCell", for: indexPath) as! TOWCell
return cell
}else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "UPCOMINGViewCell", for: indexPath) as! UPCOMINGViewCell
return cell
}
}
@IBAction func differentcellsButon(_ sender: Any) {
/// here I need call cells
}
答案 0 :(得分:0)
试试这个:
@IBAction func differentcellsButon(_ sender: Any) {
self.collectionView.reloadData()
}
答案 1 :(得分:0)
请尝试以下代码
//Declare this line on top of your ViewController
var isFirstCell = true
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if isFirstCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TOWCell", for: indexPath) as! TOWCell
return cell
}else {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "UPCOMINGViewCell", for: indexPath) as! UPCOMINGViewCell
return cell
}
}
@IBAction func differentcellsButon(_ sender: Any) {
/// here I need call cells
self.isFirstCell = false
self.collectionView.reloadData()
}