Make All Your Swift UIKit Views a UITableView

It’s possible, but is it preferable?

Steven Curtis

--

Photo by Alvin Engler on Unsplash

Imagine that you are working to create views, and making each one have subviews placed in a scrollview.

Nothing wrong with that, but it’s quite a bit of work isn’t it?

What if we use UITableView as our basic view? How would we go about something like this.

Read on to find out all the details! Please do also take a look at the accompanying code, I personally find it easier to have the whole code in front of me when looking at an article like this.

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 13.1, and Swift 5.5.1

If you’d like the video version, it’s right here:

Prerequisites:

Terminology

UIScrollView: A view that allows the scrolling and zooming of its contained views

UITableView: A view that presents data using rows arranged in a single column

UITableViewCell: The visual representation of a single row in a table view

UIView: An object that manages the content for a rectangular area on the screen

The Why

You know what, I’ve hated implementing views with UIScrollView to ensure a great user experience for some time.

Without using base classes or other methods to stop having to implement the UIScrollView in each of my views I find this rather tiresome and annoying.

I then started thinking — a UITableView inherits from UIScrollView. What if I made all of the content for my view a…

--

--