Ios 将单个单元格添加到UiCollectionView
我正在尝试在我的Ios 将单个单元格添加到UiCollectionView,ios,swift,xcode,uicollectionview,Ios,Swift,Xcode,Uicollectionview,我正在尝试在我的UICollectionViewCell末尾创建一个自定义单元格。最后一项应该是“自定义单元格”,以便用户可以添加另一条记录。尝试了一些解决方案,但没有成功。到目前为止,我的代码如下所示: func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collect
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
}
}
我也试过了,但这不是我想要的工作方式
问题是它正在取代第一个
有什么建议吗?然后最后添加该单元格:
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
}
}
我怎样才能添加一个新单元,而不是仅仅“替换”现有单元的配置??(我是iOS开发的新手)您有另一个例程NumberOfItems部分,在该部分中,您告诉集合视图视图视图中有多少项。让它返回您的_COLLECTION.count+1。@GabrielRibeiro您需要阅读以下内容: