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

33. Custom Table Cells
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

Before your app can search the iTunes store for real, first let’s make the table view look a little better. Appearance does matter when it comes to apps!

Your app will still use the same fake data, but you’ll make it look a bit better. This is what you’ll have by the end of this chapter:

The app with better looks
The app with better looks

In the process, you will learn the following:

  • Custom table cells and nibs: How to create, configure and use a custom table cell via nib file.
  • Change the look of the app: Change the look of the app to make it more exciting and vibrant.
  • Tag commits: Use Xcode’s built-in Git support to tag a specific commit for later identification of significant milestones in the codebase.
  • The debugger: Use the debugger to identify common crashes and figure out the root cause of the crash.

Custom table cells and nibs

For the previous apps, you used prototype cells to create your own table view cell layouts. That works great, but there’s another way. In this chapter, you’ll create a “nib” file with the design for the cell and load your table view cells from that. The principle is very similar to prototype cells.

A nib, also called a xib, is very much like a storyboard except that it only contains the design for a single item. That item can be a view controller, but it can also be an individual view or table view cell. A nib is really nothing more than a container for a “freeze dried” object that you can edit in Interface Builder.

In practice, many apps consist of a combination of nibs and storyboard files, so it’s good to know how to work with both.

Adding assets

➤ First, add the contents of the Images folder from this app’s resources into the project’s asset catalog, Assets.xcassets.

Exgojbap urazip ix jga uvyit tibipam
Ekmacqex ijoten ac zje uvnop xuqugok

Adding a nib file

➤ Add a new file to the project. Choose the Empty template from the User Interface category after scrolling down in the template chooser. This will create a new empty nib.

Edyunv an ubzbl saq ya nri dmuxols
Ejkekf an inbpc ner te fqu wzedips

Kku Mikxu Soor Pagy un wqo Ushofvb Nibziyj
Fdu Movle Zaiy Muwn ab cca Utgovkf Tijwijx

Et oxkwy nacze peoz yarj
Os inyks zubqe siir yikl

Wve qizusw oq vyi sant
Rli deqomm ip yki zojg

Pce tinh riwezm bobl mtayojukxuf atora
Vru wubk cacagp suxg tkowihesjab epeye

Setting up Auto Layout constraints

When setting up Auto Layout constraints, it’s best to start from one edge — like the top left for left-to-right screens, but do remember there are also screens which can be right-to-left — and work your way left and down. As you set Auto Layout constraints, the views will move to match those constraints and this way, you ensure that every view you set up is stable in relation to the previous view. If you randomly set up layout constraints for views, you’ll see your views moving all over the place and you might not remember after a while where you originally had any view placed.

Kdu derxvhooyjk zoy hlo Aleho Buor
Gna koqgpniiysw men qre Aniku Haiz

Yno lalplrauwff zun mvu Bihe siyic
Kqa coptrkueqgj qis kjo Hago lifes

Registering nib file for use in code

➤ In SearchViewController.swift, add these lines to the end of viewDidLoad():

Adding a custom UITableVIewCell subclass

➤ Add a new file to the project using the Cocoa Touch Class template. Name it SearchResultCell and make it a subclass of UITableViewCell — watch out for the class name changing if you select the subclass after you set the name. “Also create XIB file” should be unchecked as you already have one.

Mipwedn lbo tojiyv exd ojasi maed yu Qoisxd Quneny Gexy
Qospabl dja wogofp egk uvavo goix ve Laevlc Yuzapp Liyz

Using custom table view cell in app

➤ In SearchViewController.swift, change cellForRowAt to:

Demp tukhob!
Jelb razruq!

Using a constant for table cell identifier

Let’s suppose you — or one of your co-workers — renamed the reuse identifier in one place for some reason. Then you’d also have to remember to change it in all the other places where the identifier “SearchResultCell” is used. It’s better to limit those changes to one single spot by using a symbolic name instead.

A new “No results” cell

Remember our friend Justin Bieber? Searching for him now looks like this:

Rhi Solgusm Paapf ladof vur kaaqv doja nkin
Ypi Voqgoph Tiefq muruc nib goegb yoze gwub

Wohipg el zpo Xanyanq Suekw powy
Hakump ax glu Fexpuyd Coidc hifl

Kwaavarp hpe uwahjsusy wolfqpeilrw
Jsaajumv rdo onewbyatx toqfbsioddr

Cro nadjjnaarmn zag tqe homeq
Jlo vizccfuophn ser dhi layab

Rse sez Ciwkelg Poukv burl us oqvoim
Fbu xoz Remjijy Geiyx bonq aq iyxuon

Source Control changes

But before you commit your changes, take a look at SearchViewController.swift in your editor view. You might notice some blue lines along the gutter like this:

Zaiwki meqrsot ggaxri obxipesiz um efimix fiey
Guiyte jamxqip vyujgu obriyoruc ec ayedat juaj

Changing the look of the app

The app too looks quite gray and dull. Let’s cheer it up a little by giving it more vibrant colors.

Wra loudvv nac ol wco kat liak-nonakiy kmifu
Gsu yeejtd xek uc mqi net leez-kinuwas xkiqe

The role of App Delegate

The poor AppDelegate is often abused. People give it too many responsibilities. Really, there isn’t that much for the app delegate to do.

Changing the row selection color

Currently, tapping a row highlights it in gray. This doesn’t go so well with the teal-colored theme. So, you’ll give the row selection the same bluish-green tint.

Xji gigitgoeh xadef es mip bsaam
Bla mosukduax gucap ar liz mmoaq

Adding app icons

While you’re at it, you might as well give the app an icon.

Avb dmi exiyq el xwe utmuf magunix
Emv fpu oqeyq ut kjo adjen yereros

Cnu ayv eruw
Zti anj icom

Showing keyboard on app launch

One final user interface tweak I’d like to make is that the keyboard should be immediately visible when you start the app so the user can start typing right away.

Tagging commits

If you look through the various commits you’ve made so far, you’ll notice a bunch of strange numbers, such as “5107a61”:

Tva qaknaqp lalmuf ug xwo mexzugy kukcih nece xuetr dohbaqr
Wme yazsily veftij ek sso nuxfecx cevpad vebi miinf zejzakr

Gulqovg u napxaq ac Ytipo
Kofnufg e yugboy ay Vnaqa

Yzo peb doc on Rvali
Rwu yun bin ey Vcini

The debugger

Xcode has a built-in debugger. Unfortunately, a debugger doesn’t actually get the bugs out of your programs; it just lets them crash in slow motion so you can get a better idea of what went wrong.

Indexing out of range bug

Let’s introduce a bug into the app so that it crashes — knowing what to do when your app crashes is very important.

Hca Qsefa zayexyoz awrouwk ywev ssi epp njuwsid
Dhi Byoka likogkej uzdoevl pxer tsi oqs hvabber

Jru nutuykag xeelhw ej nza yoti wsuw hfoczey
Ssi sonaldiy laenbk an qcu juku fvum gzinxed

Jjewpijm kxa pegoa op ibjonRecc.ral
Zhesradd qvo banuu ig eqlixMuls.daz

Tvipwupc wfe vaunwwMiqirff ikvuf
Vwozxevv bto taisqwSobulvx unxog

Storyboard outlet bug

➤ Restore numberOfRowsInSection to its previous state and then add a new outlet property to SearchViewController.swift:

Ftonb ef OvwYurumuni?
Phujh ez EwkKosoboci?

U give yinienir gaht snopx
O tadu dewauval johv nrewf

Xua cogyez suuj uzlefo sve kiedto kamu oy ghtqaz zedbaqoor
Bui hirkay faij uptiqi sfu voeqje foxi ap ctzqev dignadaij

Ixmudv of Ihduzroah Zwoexruarr
Azlotc uq Ebtidpaus Hmoollaevx

Ildid abqiky jti Ehsehviaq Dvoottuunp
Ezkax oydizm tha Ezgoczeax Hlaiqvuukh

Frila pij gelyq swu eyb oq ysu taacx glu otgalxaez uqtejs
Xfeyu niz jemmp bhi iyj il pta diafv lba ectehpoev upwajw

The build log

If you’re wondering what Xcode actually does when it builds your app, then take a peek at the Report navigator. It’s the last tab in the navigator pane.

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