Hi everyone =D
I will show in this article how to use multiple types of cells in your UITableView or UICollectionView.
A lot of developers do that in the wrong way, using sections or rows to present another kind of cell.
- 1 - Create a model
- 2 - Register cells on your controller
- 3 - Organize it on cellForRow
First of all, I create a simple model to populate my table.
The secret of this model is the enum VehicleType. That changes everything!
After that, I create 3 kinds of cell:
And create an array of vehicles:
Ok, we are almost done! What we need to do right now is configure our
cellForRow atIndexPath or
Write an switch case to determine what kind of cell table will present. Like this example:
But, if you saw, each cell has a different size. Ok, let's do the same thing on
And that's it! Simple, beautiful, and very easy!
I don't prepared a beautiful layout on these cells, but, take a look, we have 3 different cells on the same Table or Collection:
I hope I have helped everyone looking for this change.
If you would like to extend the discussion, call me on Twitter