2016-10-20 17 views
-1

UICollectionViewCellの最後にカスタムセルを作成しようとしています。最後の項目は「カスタムセル」である必要があります。ユーザーは別のレコードを追加できます。いくつかのソリューションを試しましたが、成功はありません。私のコードは、これまでのように思える:個々のセルをUiCollectionViewに追加

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を試してみましたが、私はそれが仕事をしたいではないかそれ `s。

問題は最初に置き換えられることです。

これを行う方法の提案はありますか?

答えて

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 
    } 
} 
+0

私だけではなく、既存のセルの構成を「交換」の新しいセルを追加することができますどのように? (私はiOS開発の新機能です) –

+0

別のルーチンnumberOfItemsInSectionがあります。このビューでは、コレクションビューにビューのアイテム数を指定します。 YOUR_COLLECTION.count + 1を返してください。 –

+0

@ GabrielRibeiro http://stackoverflow.com/a/31546100/1208191 これを読む必要があります:https://www.raywenderlich.com/136159/uicollectionview-tutorial-getting-開始した –