The Programmatic UITableView Example

Implementing the UITableView without a Storyboard

Image for post
Image for post
Image of the completed project

This is a project that will help us to create a list of names as an iOS application, without the use of Storyboards. This article has been developed using Xcode 12.2, and Swift 5.3

If you would rather have a video tutorial of this please do see the following rather natty embedded video: if not you can read on!

Create a New Project

Use Xcode’s menu to create a new project, making sure to choose Swift as the language and using UIKit. Here is a detailed guide covering the same ground

Removing the Storyboard

Select Main.storyboard and delete it from the project inspector Remove Main from the Main Interface part of the general tab (this can be selected by selecting the project name at the top-left of the Project Inspector) and then select and delete Main there.

Select Info.plist in the project inspector

then expand Application Scene Manifest, Item 0 (Default Configuration), and then delete Storyboard Name you can just select, and then delete it through the keyboard button.

The SceneDelegate Code

In order to load the view controller we need some code! Replace the first function

optional func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)

with the following:

Replace the code in ViewController.swift with the following:

Run the Project

You can use the keyboard shortcut ⌘ + R to run the project in the simulator, and see the UITableView instance displayed on the screen.

Conclusion

A UITableView is an essential part of UIKit, and this guide should help you see how the project might work. Feel free to change the UITableView data - that is the String instances stored in the people array to whatever you like!

Many people choose not to use a storyboard in their project, and that is fine (they often do this to have projects that are easy for many developers to work on at the same time

The Repo makes things rather easier to follow in this project, and I do recommend you download the project to make things that bit easier for you.

If you’ve any questions, comments or suggestions please hit me up on Twitter

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store