Swift 如何在按下不同单元格的按钮时联系单元格
我有一个收集视图,我有两个不同的单元格,我需要打开应用程序时打开单元格,当您按下按钮时打开另一个单元格,谢谢您的帮助Swift 如何在按下不同单元格的按钮时联系单元格,swift,cell,Swift,Cell,我有一个收集视图,我有两个不同的单元格,我需要打开应用程序时打开单元格,当您按下按钮时打开另一个单元格,谢谢您的帮助 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { if (indexPath.item % 2 == 0) { let cell = collectionV
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
}
试试这个:
@IBAction func differentcellsButon(_ sender: Any) {
self.collectionView.reloadData()
}
尝试以下代码
//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()
}
按钮打开另一个单元格是什么意思?您的意思是它将一个单元格添加到collectionView?使用节和单元格的概念,当用户单击相应节中的节添加单元格时,尝试使用全局变量,例如var isFristCell=true,并在cell-cellForItemAt方法中使用,如果isFristCell=true返回第一个单元格,否则返回第二个单元格,和inside Differentics Cells Buton将isFristCell的值更改为false并重新加载集合视图Hello I有错误其问题中列出的UIView上UIConstraintBasedLayoutDebugging类别中的方法可能也会有所帮助。2018-04-20 03:28:48.194251-0700 TwoLive[3681:165300]-[TwoLive.MainVC UpcomingButon:]:发送到实例0x7fa27b60c030的未识别选择器2018-04-20 03:28:48.260502-0700 TwoLive[3681:165300]***由于未捕获的异常“NSInvalidArgumentException”终止应用程序,原因:'-[TwoLive.MainVC UpcomingButon:]:无法识别的选择器发送到实例0x7fa27b60c030'***第一次抛出调用堆栈:请提供完整的项目或类,以便我可以修复这一问题!