iOS: How to build a Table View with multiple cell types

Part 1. How not to get lost in spaghetti code

Stan Ostrovskiy
13 min readMay 21, 2017

There are Table Views with the static cells, where the number of the cells and the cell order is constant. Implementing this Table View is very simple and not much different from the regular UIView.

There are Table Views with dynamic cells of one type: the number and the order of the cells are changing dynamically, but all cells have the same type of content. This is where the reusable cells come in place. This is also the most popular type if Table Views.

The are also Table Views with dynamic cells that have different content types: the number, order and the cell types are dynamic. These Table Views are the most interesting and the most challenging to implement.

Imagine the app, where you have to build this screen:

All the data comes from the backend, and we have no control over what data will be received with the next request: maybe there will be no “about” info, or the gallery will be empty. In this case, we don’t need to display those cells at all. Finally, we have to know what cell type the user taps on and react accordingly.

First, let’s determine the problem.

--

--