我尝试在UICollectionViewCell
的末尾创建自定义单元格。最后一项应该是"自定义单元格"所以用户可以添加另一条记录。尝试了一些解决方案但没有成功。到目前为止,我的代码似乎是这样的:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath as IndexPath) as! EquipamentosCollectionViewCell
if (indexPath as NSIndexPath).row == 0 {
cell.imgEquip?.image = UIImage(named: "novavisita")
return cell
}else{
cell.backgroundColor = UIColor.green
return cell
}
}
我也试过了this solution,但这并不是我想要的方式。
问题在于它取代了第一个。
有关如何做到这一点的任何建议吗?
答案 0 :(得分:0)
然后最后添加该单元格:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath as IndexPath) as! EquipamentosCollectionViewCell
if (indexPath as NSIndexPath).item == YOUR_COLLECTION.count - 1{
//Add New Record Cell
cell.imgEquip?.image = UIImage(named: "novavisita")
return cell
}else{
cell.backgroundColor = UIColor.green
return cell
}
}