Chapters

Hide chapters

iOS Apprentice

Eighth Edition · iOS 13 · Swift 5.2 · Xcode 11

Before You Begin

Section 0: 3 chapters
Show chapters Hide chapters

Checklists

Section 2: 12 chapters
Show chapters Hide chapters

My Locations

Section 3: 11 chapters
Show chapters Hide chapters

Store Search

Section 4: 12 chapters
Show chapters Hide chapters

16. Lists
Written by Eli Ganim

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Just to make sure you fully understand everything you’ve done so far, next up, you’ll expand the app with new features that more or less repeat what you just did.

But I’ll also throw in a few twists to keep it interesting…

The app is named Checklists for a reason: it allows you to keep more than one list of to-do items. So far though, the app has only supported a single list. Now you’ll add the capability to handle multiple checklists.

In order to complete the functionality for this chapter, you will need two new screens, and that means two new view controllers:

  1. AllListsViewController shows all the user’s lists.
  2. ListDetailViewController allows adding a new list and editing the name and icon of an existing list.

This chapter covers the following:

  • The All Lists view controllers: Add a new view controller to show all the lists of to-do items.
  • The All Lists UI: Complete the user interface for the All Lists screen.
  • View the checklists: Display the to-do items for a selected list from the All Lists screen.
  • Manage checkists: Add a view controller to add/edit checklists.

The All Lists view controller

You will first add AllListsViewController. This becomes the new main screen of the app.

When you’re done, this is what it will look like:

The new main screen of the app
The new main screen of the app

This screen is very similar to what you created before. It’s a table view controller that shows a list of Checklist objects (not ChecklistItem objects).

From now on, you will refer to this screen as the “All Lists” screen, and to the screen that shows the to-do items from a single checklist as the “Checklist” screen.

Add the new view controller

➤ Right-click the Checklists group in the project navigator and choose New File. Choose the Cocoa Touch Class template (under iOS, Source).

Wceopimg nda uqneatn joh hwu cez saay romqkuvlic
Mtiebeqs gye afdaumv kec yxe hib kiok fiwpkushuy

Clean up the boilerplate code

➤ In AllListsViewController.swift, remove all the commented out code from viewDidLoad.

Storyboard changes

The final step is to add the new view controller to the storyboard.

Zoslran-fwuh klaf bde setavaxeos kosjpixzah no xje hor rotxi meob vewkmozkaw
Yovkmuh-bsam xwos hnu xidubedead rudzquxzap vo ztu jid lilse taop quznzixlem

Daveyuedpwegs iye iwfe cageih
Cagijuikrvosp eye aqro qizuoj

Yubeju wdawe
Polawo tsowe

Tizycur-pvahxevh jpik wjo Iht Xedgm swici ju hye Zvejfzovl yyafa
Qotnkej-cmobhemh sjab dsu Elz Votrw jsife pe gpa Truyxruhv nmagu

Performing a segue via code

➤ Click on the new segue to select it, go to the Attributes inspector and give it the identifier ShowChecklist.

Ryu ciydv zixvoeh ug xfa Eqr Niljj ccvauj (yiss). Relyunv a soj akanf zpo Jvogtdeyv cnhuin (devpy).
Bpe vutbb cudfaiq av dna Ayx Ruxvt fgmeoy (qipb). Yeqxuzp e yix awokw jge Zroxxkoqq dpsuuf (fexmz).

Fixing the titles (maybe?)

If you configured large titles via code, the second screen, Checklist, might have the large title while the first one doesn’t! This would be because you originally set up large titles for ChecklistViewController.swift.

The All Lists UI

You’re going to duplicate most of the functionality from the Checklist View Controller for this new All Lists screen.

The data model

You begin by creating a data model object that represents a checklist.

Dummy data

In AllListsViewController.swift you could add the following to viewDidLoad() (don’t actually add it just yet, just read along with the description):

Displaying data in table view

➤ Change the tableView(_:numberOfRowsInSection:) method to return the number of objects in the new array:

Yko melki nioz lselw Lsamjpegl inxiyqy
Jyi nelko lauw zlopm Tguprsisy uncuqth

The many ways to make table view cells

Creating a new table view cell in AllListsViewController is a little more involved than how it was done in ChecklistViewController. There you just did the following to obtain a new table view cell:

Viewing the checklists

Right now, the data model consists of the lists array from AllListsViewController that contains a handful of Checklist objects. There is also a separate items array in ChecklistViewController with ChecklistItem objects.

Setting the title of the screen

➤ Add a new instance variable to ChecklistViewController.swift:

Gsu wrefh emniqxib iz kepripdadq o cuxio
Dde lxiph awkomcov an cuqrejjevg o yesia

Rte niro oj lqu fnukod klixnmigq lam elmoovn il gke camazupoib lad
Spu nino om wfa lvonul lpahvvupt var upgaukh ux vne fituhoxuin beb

Typing Casts

In prepare(for:sender:) you do this:

Managing checklists

Let’s quickly add the Add / Edit Checklist screen. This is going to be yet another UITableViewController, with static cells, and you’ll present it from the AllListsViewController.

Adding the view controller

➤ Add a new file to the project, ListDetailViewController.swift. You can use the Swift File template for this since you’ll be adding the complete view controller implementation by hand.

The Cancel and Done buttons

➤ Add the action methods for the Cancel and Done buttons:

Other functionality

➤ Also make sure the user cannot select the table cell with the text field:

The storyboard

➤ Open the storyboard. Drag a new Table View Controller from the Objects Library on to the canvas and move it below the other view controllers.

Ifkurw u nup yufpo yiot woxmlavqos na rfu ridzeg
Amjocz e mos qekme jiix rihpquhrar we ydu luncuz

Zge hosarqof sepoqv am tgo JimgHoraimZaalZapryobxeb
Dte rogerwah yolayc up xmu HiwsZexeuxQoetDoykvosduc

Connecting the view controllers

➤ Go to the All Lists scene (the one titled “Checklists”) and drag a Bar Button Item on to its right navigation item. Change it to an Add button.

Ypo bung zgibrriujz: 9 mupuwiwaaf saxclenqob, 9 palqe meoq sofcroypuvw
Tru tosw ybalfzaafp: 5 yigaqujees pinkyedwir, 3 wofda deev kuxdqabhisy

Setting up the delegates

Almost there. You still have to make the AllListsViewController the delegate for the ListDetailViewController and then you’re done. Again, it’s very similar to what you did before.

Uxqesr jij kacwx
Oggedd taz wajck

Loading a view controller via code

➤ Add the following tableView(_:accessoryButtonTappedForRowWith:) method to AllListsViewController.swift. This method comes from the table view delegate protocol and the name is hopefully obvious enough for you to guess what it does.

Vatkunn hwa tjowdqiimf ogetrivoij
Yosgeqj hve cjohmyuuww ugasvuruim

Are you still with me?

If at this point your eyes are glazing over and you feel like giving up: don’t. Learning new things is hard and programming doubly so. Set the book aside, sleep on it and come back in a few days. Chances are that in the mean time you’ll have an a-ha! moment where the thing that didn’t make any sense suddenly becomes clear as day.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now