POP UITableView

iOS Dev
3 min readApr 17, 2021

Hi everyone. Let’s look at the code snippet below:

When you see a UI of simple tableView you can have a temptation to make things as easy as possible and probably that way could look pretty useful. But in real life, design changes very fast and the code from snippet above comes to something like that:

Yep, that bad guy is not going to joke with you. The code from a very simple solution swiftly grows in complicity and bad readability. And if you have a bad luck and you have to edit something here, you’ll spend a lot of time trying to understand how all those conditionals and rows work.

So, we can use much simpler, in my opinion, way to implement our tableView UI. Use POP for this. TableVIew consists of Rows, Sections, Headers and Footers. Let’s create according protocols for them.

Also 2 protocols for setup our cells and FooterHeaderViews:

Preparations are done. Let’s create some extremely simple example. Our app describes info about a farm. The app has three sections: animals, host and equipment. For my example I use MVVM pattern. So let’s create it! I’ve implemented default struct Section which I’m using in most cases, also created a header example.

Next step is implementing models for our cells.

Implement FarmViewModel.

Almost done. Setup our controller.

Like you can see from the code snippet above, no matter how many different cells you have the tableview setting up code inside datasource and delegate will be the same.

From the UITableViewCell side you have just to make type cast and you could use a model to setup the cell.

That’s it. Other cells and headers work in the same manner.

How do you work with difficult tableView based designs? Feel free to tell your tips and tricks in comments.

--

--