Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将单个单元格添加到UiCollectionView_Ios_Swift_Xcode_Uicollectionview - Fatal编程技术网

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您需要阅读以下内容: