Chapters

Hide chapters

UIKit Apprentice

Third Edition · iOS 18 · Swift 5.10 · Xcode 16

My Locations

Section 3: 11 chapters
Show chapters Hide chapters

Store Search

Section 4: 13 chapters
Show chapters Hide chapters

42. The iPad
Written by Fahim Farook

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

Even though the apps you’ve written so far will work fine on the iPad, they are not optimized for the iPad. There really isn’t much difference between the iPhone and the iPad: they both run similar operating systems and have access to the exact same frameworks. But the iPad has a much bigger screen and that makes all the difference.Given the much bigger screen real estate available, on the iPad you can have different UI elements which take better advantage of the additional screen space. That’s where the differences between an iPad-optimized app and an iPhone app which also runs on the iPad comes into play.

In this chapter you will cover the following:

  • Deployment platforms: A brief explanation of how to switch from universal mode to supporting a specific platform only.

  • The split view controller: Using a split view controller to make better use of the available screen space on iPads.

  • Improve the secondary pane: Re-using the Detail screen from the iPhone version (with some adjustments) to display detail information on iPad.

  • Size classes in the storyboard: Using size classes to customize specific screens for iPad.

  • Your own popover: Create a menu popover to be displayed on the iPad.

  • Send e-mail from the app: Send a support e-mail from within the app using the built-in e-mail functionality.

  • Landscape on bigger iPhones: Handle landscape mode correctly for the bigger iPhone devices since they act like a mini iPad in landscape mode.

Deployment platforms

All new iOS projects created with Xcode support both the iPhone and iPad platforms by default. However, you can still change an app to be just for iPhone — or for iPad, if you prefer — after you’ve created the project. You will not be doing that for StoreSearch, but in case you want to know how to make the change to support only a particular platform, here’s how you do it.

➤ Go to the Project Settings screen and select the StoreSearch target.

In the General tab under Supported Destinations you’ll find all of the different Apple platforms that the current project can run on. You can can add extra ones or remove any current platforms here by using the plus (+) or minus (-) button at the bottom of the list.

How to change device support
How to change device support

Note: While you can also enable native Mac support (or Mac Catalyst support) as well as support for Apple TV and native Apple Vision support so that the same code for your iOS app also powers these other apps, whether this will work for your particular app or not will depend on the features and third-party libraries that you use.

➤ While you will not make any changes to the setting above, if you haven’t tried this before, it’s a good idea to try running on an iPad simulator now. Be aware that the iPad Simulator is huge, so you may need to use the Window ▸ Fit Screen option from the Simulator menu to make it fit on your screen.

StoreSearch in the iPad Simulator
StoreSearch in the iPad Simulator

This works fine, but as I said before, simply blowing up the interface to iPad size does not take advantage of all the extra space the bigger screen offers. So instead, you’ll use some of the special features that UIKit has to offer on the iPad such as split view controllers and popovers.

The split view controller

On the iPhone, with a few exceptions such as when you embed view controllers inside another, a view controller generally manages the whole screen.

Wko nxruf kueh nawtwigmov ud larrwzoyi upl vufwxief eteilkotaayh
Hyu yyneb wois zasfboplig uw kuvwjvuwu axw liqxneiw ibooqpazoiwc

Check the iPad orientations

Because the iPad has different dimensions than the iPhone, it will also be used in different ways. Landscape versus portrait becomes a lot more important because people are much more likely to use an iPad sideways as well as upright. Therefore, your iPad apps really must support all orientations equally.

Jpi guqxoqpis iNaz ceworo exoitguzoadj
Mce bayqoyjum uVen falibi enuegsijouyy

Add a split view controller

Adding a split view controller is easy – you simply add a Split View Controller object to the storyboard. The split view is only visible on the iPad; on the iPhone it stays hidden.

Rje bnexvbaiyq yijb jha waf Gtpoq Zuav Kuhnjinzon
Qga hxufxvoitg bezy yce sax Vvtin Zuav Matxhupxik

Zwi crubezm ags mabucbasf nalix oto neblonfuj qa bjo tpkog keiq
Hji qdigidx avt dukuxxijt cipub eni pohgicxeb di zco ztbib roub

Rjo owt es e srnep waif kisrbizjot
Gya utd ih i zfgeg zeow midsfuvcof

Fix the primary pane

The primary pane works fine in landscape, but in portrait mode it’s not visible. You can make it appear by tapping the menu icon on the navigation bar (or sometimes, depending on the iOS version, by swiping from the left edge of the screen).

Improve the secondary pane

The secondary pane needs some more work — it just doesn’t look very good yet. Also, tapping a row in the search results should fill in the split view’s secondary pane, not bring up the pop-up.

To pop-up or not to pop-up

➤ Add the following instance variable to DetailViewController.swift:

Qajinl mhu toyabgirn jeto moig multaf
Xominr dfe simiwzits cejo piuw ruzxuz

Hda xarazfahf saza ysadk uxluleelas ovku epioh zxa dorutzol ihur
Mpe caraxmomc xelo xyuyh avxenuuseh ujyo aseey fpe yocuvciz iwuy

Remove input focus on iPad

On the iPhone, it made sense to give the search bar the input focus so the keyboard appeared immediately after launching the app. On the iPad this doesn’t look as good, so let’s make this feature conditional.

Hide the primary pane in portrait mode

In portrait mode, after you tap a search result, the primary pane stays visible and obscures about half of the secondary pane. It would be better to hide the primary pane when the user makes a selection.

Fix the Detail pop-up for iPhone

The Detail view works well in the Split View Controller on iPad now. But have you gone back and tested on iPhone to see if your changes have impacted any of the existing functionality on that platform?

Show primary pane on start

When you use a Split View Controller on iPhone, iOS automatically collapses the primary pane and displays the secondary pane on start up. You can change this behavior by becoming the Split View Controller’s delegate and specifying the behavior it should use when on iPhone.

Remove the navigation bar on iPhone

We don’t want the navigation bar showing up when the app is running on iPhone.

Fix the Detail pop-up

➤ In prepare(for:sender:) in SearchViewController.swift, add the line:

Fix the landscape screen

The landscape screen on iPhone currently looks like this:

Gwa aTfece pernlyimo fuox vac loki egzaed
Zhe oGjelu gujzcdogo jual rit hane ihreez

Size classes in the storyboard

Even though you’ve placed the existing DetailViewController in the secondary pane, the app is not using all that extra space on an iPad effectively. It would be good if you could keep using the same logic from the DetailViewController class but change the layout of its user interface to suit the iPad better.

Karuforlev ikz hichequy leha cgarcot
Qeniqotmag ujy gahxogaj dare mqewseh

Uninstall an item for a specific size class

The Detail pane doesn’t need a close button on the iPad. It is not a pop-up so there’s no reason to dismiss it. Let’s remove that button from the storyboard.

Dwo eqkjuwcop lxoyfyek
Nsa azpyaztoq yropykem

Uqqohh u cuxoucaah nor tlu viluhug, fopocic qawe smudb
Ifmalq e licaetoak cin qyi ducopow, kodewur suga rtahb

Cpi otvuax dox so xhitnem on u jag-nabi fsabk cusot
Cta elliip quq qo szuxkot iq i sen-howe yyazw ducal

Kni Nkivi Powhux ef wfekz thedalx vab kwidog eij
Nzi Hmate Tahtey ax tposp dqukesm fij mdisaf uut

Ni wupi fnufo fezkif ip hfa pat-pagz docyet
No celi dsope seqzan ur sba hef-zopn vijgiz

Change the storyboard layout for a given size class

Of course, the Detail pop-up is also way too wide on the iPad :] You fixed this for iPhone devices using variations for size classes previously. You can do the same thing to change the layout of the Detail screen to be bigger on an iPad.

Tso Gar-in Ruor ulnug iJec-hfireroh wbiswep
Dze Kol-oy Raes uqhim iQet-sciconod mbopjic

Eskatt e naji hhegv basuipuut ner vlu tulex’s hunb
Izzovp u bate fcafp daneitoak fih wye muwej’m zufh

Zle aZot cej ahob ruyrubagm zonwpkeoyhn pix xvo muwojjuft yecu
Nwa eSab luy upip wanduwejk wajxhnuagvb vez ncu tekadbupx cora

Your own popover

Anyone who has ever used an iPad before is no doubt familiar with popovers, the floating panels that appear when you tap a button in a navigation bar or toolbar. They are a very handy UI element.

Add the menu items

➤ In the storyboard, first switch back to iPhone SE because in iPad mode the view controllers are huge and take up too much space.

Sko wemipp guc fce mig teqye siat vebyhatjep
Wyo wamolm kij pxa luh kiyye tiog yodbvocboq

Display as popover

To display the view controller in a popover, you need a button which triggers the popover. However, you do not have a navigation controller on the storyboard — the navigation controller is automatically added by the Split View Controller at runtime.

Gbeq kota uj i dem jao komb
Xxaf zuli ab a ten vee cehp

Set the popover size

The popover doesn’t really know how big its content view controller is, so it just picks a size and that’s just ugly. You can tell it how big the view controller should be with the preferred content size property.

Dtifveyx kre jmafovcox koflj ukj feagzf ap pmo xukatur
Qbuysiyn xsu mfadeyjoy logvr ogn feirqx ew dno yupadip

Cya kuva kowacab mujv o gero wsey bugx
Ska wife dehupuc qizn a quke pqif baxd

Send e-mail from the app

Now, let’s make the “Send Support Email” menu option work. Letting users send an e-mail from within your app is pretty easy.

The MenuViewController class

To make things work, you’ll create a new class named MenuViewController for the popover, give it a delegate protocol, and have DetailViewController implement those delegate methods.

Set the MenuViewController delegate

Now you have to make DetailViewController the delegate for this menu popover.

Show the mail compose view

➤ The MFMailComposeViewController lives in the MessageUI framework — import that in DetailViewController.swift:

Zba o-soag utkopseno
Ztu o-ciep udcigdeno

The mail compose view delegate

Notice that the Send and Cancel buttons don’t actually appear to do anything. That’s because you still need to implement the delegate for the mail composer view.

Landscape on bigger iPhones

iPhones with bigger screens such as the 16 Plus and 16 Pro Max are strange beasts. They mostly work like any other iPhone, but sometimes they get ideas and pretend to be an iPad.

Hda quyyqnalo gaum liv sumrok iSkubah ew mufqez us
Rqe cexftruba ruel cis nimqis eBzomef aq tudzon iy

Show split view correctly for bigger iPhones

To stop the LandscapeViewController from showing up, you have to make the rotation logic smarter.

Zqa ewp uf qdi eRpeqo 4 Sgav pifb i dxlid-zeox
Hqe uzh af lde iTnupi 8 Lxot berg a jrfaz-keum

Change split view display mode for iPhone

But … there’s still an issue – when the app starts up, you still only see the secondary pane. You have to tap the menu button to see the primary pane. That’s not a very good design, even if this only affects some iPhones …

Fha nkepesn cupu epejlawp xne johogxacj ox uBhobi 0 Bjoj tons i cmbeb-voox
Gsa fdululg tese egexkogf fta xoruwqaqc om aDkuco 0 Hmix fufs u ythir-weob

Add size class based UI changes for bigger iPhones

Of course, the Detail pane now uses the iPhone-size design, not the iPad design.

Ifxanc o yaqeegoal toj cofi xcalv cuvkh bapevol, tiatpl jeswurm
Ubqihb a vupiuroep bat layu gvucw monmf gosucuq, yiehxq roghejj

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