あなたは、あなたがnumberOfItemsInSectionとcellForItemAtIndexPath機能を実装する必要があり、あなたのViewControllerにUICollectionViewDelegateとUICollectionViewDataSourceプロトコルをサブクラス化する必要があります。 さらに、ストーリーボードに2種類のセルを作成し、サブクラス化する必要があります。AddedPlayerCellとDefaultCell各セルには、というラベルが付いていると仮定します。 labelTextもあります。 2つの異なる細胞タイプを管理するために
let players = ["Player1","Player2"] //players added till now
let numberOfCells = 5
//Here you set the number of cell in your collectionView
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return max(players.count,numberOfCells);
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if((indexPath.row + 1) < self.players.count){ //If index of cell is less than the number of players then display the player
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("yourIdentifierForAddedPlayerCell", forIndexPath: indexPath) as! AddedPlayerCell
cell.labelText.text = self.players[indexPath.row] //Display player
return cell;
}else{//Else display DefaultCell
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("yourIdentifierForDefaultCell", forIndexPath: indexPath) as! DefaultCell
cell.labelText.text = "Add"
return cell;
}
}
あなたがしようとしているかを示すことはできますか?どの部分が正確に問題を抱えていますか? – Paulw11