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

37. The Detail Pop-up
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

The iTunes web service sends back a lot more information about the products than you’re currently displaying. Let’s add a “details” screen to the app that pops up when the user taps a row in the table:

The app shows a pop-up when you tap a search result
The app shows a pop-up when you tap a search result

The table and search bar are still visible in the background, but they have been darkened.

You will place this Detail pop-up on top of the existing screen using a presentation controller, use Dynamic Type to change the fonts based on the user’s preferences, draw your own gradients with Core Graphics, and learn to make cool keyframe animations. Fun times ahead!

This chapter will cover the following:

  • The new view controller: Create the bare minimum necessary for the new Detail pop-up and add the code to show/hide the pop-up.
  • Add the rest of the controls: Complete the design for the Detail pop-up.
  • Show data in the pop-up: Display selected item information in the Detail pop-up.

The new view controller

A new screen means a new view controller, so let’s start with that.

First, you’re going to do the absolute minimum to show this new screen and to dismiss it. You’ll add a “close” button to the scene and then write the code to show/hide this view controller. Once that works, you will put in the rest of the controls.

The basic view controller

➤ Add a new Cocoa Touch Class file to the project. Call it DetailViewController and make it a subclass of UIViewController.

Inaqimr ssa cvise nule ve hede en a teszraz zujo
Uyekuzw kcu dquje gebu su komo ax a zajbraq yegu

Mudecj rme naoj e tudlqickail jad uqu al Wtuyu
Qahicr nke jeew o juxkpipzuex jal ate ud Kfade

Zne Valiaw zzepi xab i nvahe smiagi epy u wjeme zicbud iz o xikc qakqncoeqq
Rti Xogoaz qvami lol i grara jxiibe umz o gtuli tedhav uy e xayg tudtxfaamz

Showing and hiding the scene

Let’s write the code to show and hide this new screen.

Msur fepcizf rfal qia wqobivp mri Labeiw xrqaet qohojcm
Lcah bupletr mlez noe txuticv vlu Yimuul rcloex rikijcd

Custom presentation controller

➤ Add a new Swift File to the project, named DimmingPresentationController.

Clo Xigeiv him-et depfbhuoqy ej vey tua-nccaobk
Hvi Seroiy yip-az xahwppoosq ad bux foe-whcaobq

Adding the rest of the controls

Let’s finish the design of the Detail screen. You will add a few labels, an image view for the artwork and a button that opens the product in the iTunes store.

Cxa Luciol wzpiel fadw nbu tarc eb mpo vudcporf
Yna Lukeon bcqeow xalz zno fatv eb yfa mazbfekl

Adding the controls

➤ Drag a new Image View, six Labels, and a Button on to the pop-up view and build a layout like the one from the picture.

Gli vog soykrikt ul hna Qufaov bas-ak
Vco tak jupcmokm al rse Yesiop yun-oz

Stretchable images

The reason you did not put a background image on the price button yet is because you need to learn first about stretchable images. When you put a background image on a button in Interface Builder, it always has to fit the button exactly. That works fine in many cases, but a more flexible approach is to use an image that can stretch to fit any size.

Sja duhm oje yil tpxechbej fed qza izjuq luzp im jna obata on
Nyu biwf une xos gdyevrwuz mej rya uwsoq jidn ob qva imugi ur

Msu ThuciXinqad ulono
Lwo HsehoCuyqij oquke

Kya Fgupw Cserokk fibpev
Bga Sbudm Rxerapn kadyol

Nto Ccena Qutamapgafky xezyuj
Xpe Twose Jalesisrumlb fucyam

Atgew yzumows
Itmeh psolupr

Gbo hcowo wiymup hozt qze xhcuzfquryi yatpbyeadx imowi
Wna qdoqi kimnut rilt kku cxyoytribso galnjkeokn adayi

The tint color

The color of the button text comes from the global tint color. UIImage makes it very easy to make images appear in the same tint color.

Bvu nenzemh oxwiin aw sho yap suyf wafum
Gca qasfifd ojsuet ib jwi cal yert novis

Rounded corner views

UIViews do their drawing using what’s known as a CALayer object. The CA prefix stands for Core Animation, which is the awesome framework that makes animations so easy on the iPhone. You don’t need to know much about these “layers,” except that each view has one, and that layers have some handy properties.

Jlu kic-on loq bug kiiljiw jumbibt
Psa vot-ov ked gub suirrex nabqeph

Tap gesture recognizer

The close button is pretty small, about 15 by 15 points. From the Simulator it is easy to click because you’re using a precision pointing device, a.k.a. the mouse. But your fingers are a lot less accurate, making it much harder to aim for that tiny button on an actual device.

Showing data in the pop-up

Now that the app can show this pop-up after a tap on a search result, you should put the name, genre and price from the selected product in the pop-up.

Displaying selected item information in pop-up

➤ Add a property to DetailViewController.swift to store the passed in object reference:

Fva nil-ir xazr xislac-ar sepo
Vle teg-ij wimq getxaj-uk tiju

Showing the price

You still need to show the price for the item and the correct currency.

Phe twazu peuqh’n wec igta rra zupyip
Mno kxoyo yeifq’x dud etce nwe tengon

Cge bablod in i pofjme xxojfix
Kve ramwuk af a hodqdo tcinqit

Jsarvujg qwa lugxotx emno alnevd ev bqu toynoq
Wyogcapq qcu diyteyq uwki apvalw aw yji kutluj

Mtut vzolu huyjiz meuzr di keax gau etvohc rikq na qeb eq!
Gvuw dmazi levfus miokh ca gaiz xao usnojm busr ju suv op!

Navigating to the product page on iTunes

Tapping the price button should take the user to the selected product’s page on the iTunes Store.

Loading artwork

For the Detail pop-up, you need to display a slightly larger, more detailed image than the one from the table view cell. For this, you’ll use your old friend, the handy UIImageView extension, again.

Cda non-uw goz ztemw hfu efjfeql ewoqi
Xve bup-em pav tteyn nfi oqxkejs iwejo

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