I'm working on a "trading" application where I would like to have a static number of cells.
On load, users will see 5 cells, each displaying a label that says "Add."
When a "player" is added, that cell displays the players information, the other 4 cells still display the "Add" label. Another is added, 2 cells have player information, 3 have the "Add"
I'm having a hell of a time with this. Can anyone point my in the right direction? I have custom labels setup, I think my logic may just be off on how to perform this correctly.
You need to subclass the UICollectionViewDelegate and UICollectionViewDataSource protocols in your viewController, then you need to implement the numberOfItemsInSection and cellForItemAtIndexPath functions. Additionally to that you need to create two type of cells in your storyboard and subclass them, in the following code i will suppose that you call AddedPlayerCell and DefaultCell your cells, i will suppose that each cell has a label called labelText too.
In order to manage two different cell types, you can:
"Add"
and the other"Info"
. The"Add"
cell prototype will contain the label"Add"
, and the"Info"
cell prototype will contain fields to display the player info.var showingAdd = [true, true, true, true, true]
In
cellForItemAtIndexPath
, check theshowingAdd
array to determine which identifier to use when dequeueing the cell:When a cell is selected in
didSelectItemAtIndexPath
, check if it is showing add and then process it accordingly: