The UITableView Example

Implementing the UITableView with a Storyboard

Image of the completed project

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

If you want a video guide, I’ve got you covered! Also please do download the full code from the repo and read / watch along!

Create a New Project

Use Xcode’s menu to create a new project, making sure to choose Swift as the language and using UIKit. detailled guide

Add the Code

Replace the code in ViewController.swift with the following:

Add a UITableView instance to the Storyboard

Go to Main.storyboard

Press the plus (+) sign at the top of the Xcode window there is a plus (+) sign.

Select the tableview, dragging this into the ViewController (the white rectangle) on the storyboard.

Drag the handles to make it the same size as the ViewController.

Connect the outlets

Use the keyboard shortcut ⌃ + ⌥ + ⌘ + T. (Control + Option + Command + T) to be able to see both the Storyboard and the ViewController on the screen at the same time (you must have the Storyboard on the screen for this shortcut to work).

Use the key ⌃Control to drag from the hollow circle on the left of the @IBOutlet var tableView: UITableView! to the UITableView on the UIStoryboard.

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.

Nice!

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!

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