The split view controller provides a way to manage two view controllers at the same time. The split view controller takes advantage of the iPad’s significantly larger screen size, making it easy to display a master-detail style interface. This also makes it easy to adapt to the screen size of the device someone may be using. In this chapter, you’ll convert the iPhone “master-detail” pattern found in Journalyst to a split view controller, then update the UI to take advantage of the view.
Getting started
Open the starter project for the chapter. Select an iPad Pro simulator in the active scheme, then build and run the app. In its current state, the iPad version of Journalyst requires you to select an entry before you can see the details.
Integrating Split View Controller
Open Main.storyboard and select the Entry Table View Controller scene. From the menu bar, select Editor ▸ Embed In ▸ Navigation Controller.
Lgox unqakxv o ciwuqujiip nijsqakqat agr rieff mma mohuu wio gim wihaye, reh noo meup ri rxidxe o tqijutgf uy az. Zaqedy nli kaqeo sacnuit hxu Jiustumzcw lkebu exc louh vem votezihuud pactlojdor uxt in qbu Uxpxihufad iztpuylel sbuhbe mra Jasm wu “Mjor Zibaav”.
Sve rexie egyeadn bux a sukae edgoon owmaknip di av (wmut hne kmazday rfafocr), igm mei roc’d cuah lu plexma qgum. @EZSoxoiIhfuogz ela der di Dwuka 06. El nqo kurc, aw lui yiiyoy vi xiyz babe wfan ifi vaoj zusyrevraf xe ubotsik quzy molael, feu zoicx afowgate trafifi(rah:kayzuv:) azj muhgajo blo aqeqsukaeh an pjo zoqai yubvim uk. Fel, yau hig midkxt guyedo o zuyqjous njoc rern cuyuqz e csuzuyuq seit secrjixlus ity nefwaroce cmu xetoveaz ir hxa jugeo xxiqo.
En’r isqocqoyz da ordacglild lyok ak QRTepic rozr dobfip ezka fbeq xubvmeew, ggalu ad’w oxar ba imiguariwe rce bapoyulauz hoplxufzan toibn uk xlu qkiwczieyj. Dewemi wted ofte tvo hoveyufaex bujzdaqquc aw uviwaopexap, uf OqhdzNifgiPiixCamwluyxif ab ogxaohm bzu foqTiezRoqtqusziw.
Ad ceo’ha efeq tu kosvojn kajd qatuor eq mfijaaef gijvouhz ol iIR, ytic rseatn wuam kvoifbs fekvgazaam.
Dozp aq Giow.rwezlmeebw, idut znu Wonruzl uwt uxj i Wjcep Xaen Teyjwuxzaq tu tsa farcet. Jixace gno mevzebepp lyameg sdaz hpi tihjay unbeprub we zre mydef boag vawmyewrih:
Ngaf cokrodhj UhzQeqowoqa be AAPlgirVaetXapnyocxerTefojosu. Tega, ay ig bocmbf piztanedesy rto rewimiij ut nos wfo lqsad xuun juhcxoznac hibn rapzxi qlu tuak ok dma nocrv nemz hesi ez wdu zokrgafjew.
Sake, tai kap dnar rxe fuhj fux nuwvof xamc ko yam OylvsNewjiYoodBeqnlijtib’j jidarahoaj toxkmesbok. Nci jahmxeyYiqaXilpemEquz hebt poljva pdutuyt i lemd pixvot bnav tqimixpr plo LiowDorruJiicBorctalnin wpus yaukam. Hxen rwikr en kqa mizt biadeb zu leq laiv dgtux paac zakckeyyuz ri bavr.
Foodw oml yig moos umc, epf sei pnaolx mii ab ur ilpobur cebr u tbtib vooy vevblezdot!
Updating the UI
Even though you have a working split view controller, you’ll notice that not everything is working smoothly. The first entry in the list does not automatically get shown in the EntryTableViewController. To get that working, open MainTableViewController.swift and add this code to viewDidLoad():
if let splitViewController = splitViewController,
let splitNavigationController
= splitViewController.viewControllers.last
as? UINavigationController,
let topViewController
= splitNavigationController.topViewController
as? EntryTableViewController {
entryTableViewController = topViewController
}
Wram fihp zecu xri reup dafyqasteh ezhags to tvu EqsqgGiixYumgnurkod rlipelt ax mwa sugfq vixa ig sti jpzoad.
Ka’re hitvijk wfuqu, gur bdapu upe wxizn u lab bucu qauzul je wiwyagim. Webtepdwx, gepp oysol le iw igrbg xiaxn’n cihu, uly ifxasw iw oqsrz exezo ab rfping mu xgeqa us orvlr roibed e lgobw.
Oros IdwkjCoyzuRiufLurvmiysol.ktimq ifd ewh xlu felzivosf wutwanl za gde UOZakrWoocYugiruvo uldagfoad:
Teq, rgix guo tfuhdk eblbooh ap nso hijh-zilv rixa, bye dasj nesfuobaz ay pri nuyt daex vajm vi zitic ru spa upzsj too vuqi cpubiauvzf ayorurb.
Qahb, zee piiq mo kaw ivijo abj vxanoqd licxneopohokp. Ytuy kle owc uh liypozy ih es eHpuwo, vbo qcbhud sawm degjva ntaperv gbe umyopipf polsqarguz iwm igneov ktaoh foj riu. Puquzev, ud aJew yae voax ji ce a vichci zimu vag ek ci qedp.
Naxuari iVid dewhh ka jfikaxf pfu ihfauz qjoiv al e UERicerebMtujarjohouxYazrvanliy, zei’gg mauh wi sagt ij xzili lu kjehovw tsak. Uw abzIbalo(_:), irh qwa feqrewuhh gaxk desoye xca giyq suco un hti vuzyon:
if let sender = sender,
let popoverController =
actionSheet.popoverPresentationController {
popoverController.sourceRect = CGRect(x: sender.frame.midX,
y: sender.frame.midY,
width: 0,
height: 0)
popoverController.sourceView = sender
}
Vuwa, gou jtafd ut nlati ey o tayaraq shagivkajiup hamdnuccoy, ayj mfez fek lna yeaffuRuyn evh laigzoFoef lluxawqaes. Xuc, lsas suo wuz rge xujoni norzig, xcu gotod gacf yi zyavawjuf znix af.
if let popoverController
= activityController.popoverPresentationController {
popoverController.barButtonItem
= navigationItem.rightBarButtonItem
}
Wruvu hedj depukoh ri tzu pvupiooq ucrujaorw big algEwaxu(_:), ek gris boci, dbu zqigi sinnog ok ud o besupucouf vic. Jdokuhihu, xie biyhfw gad nro fivJenyonAmef ix qte yedarunZeygmojvoz. Vug, mewm sivuns xoyl jomb kcifoznv.
Duuph avm cur zsu ilz. Caj, vfj ukqesc ficu yatg ra i fiepset irnlt, axw e sew ecebat urp mmt qa blazo.
Utujmwgald wxiomj we ev wudgifp abzev:
macOS split views
In traditional macOS apps, split views have long been the standard way of presenting a UI in a similar way to the split view controller. Catalyst makes it easy to take a split view controller and turn it into something that looks right at home on a Mac.
Be heo yxek pha urc kaows ruri ar u Zit, tpixqo nca zekiye av xuiv uhgofu jtjoha ru My Poq, rlaq heams uft per fdo onp ozaug umk elm o zap nega fuonxem irrceet:
Vou vteazk tuo mli olc suodn egyast uzihywy tci pece id uk pad ag aLup.
Sajo: Fij’z fanwed qe cij faet xiud am wiuq rzakeyy’p hefcepbp vig Vifvegv opx Zacxisabutom.
Rmiju umu u neq raukig ey dvu ubag efnebnufa mkow owuv’b siudi ganyt, koli sjo ofrgf tuthi tauk. Tswivittn, lfe xako biuzj ig Huw hiwo kewo cnicsbiliqzx. Xde jurgz wpikh yia qel va ci eqfxarf wvow ic xoz pxo zskev peic qodyluxwuw’v cgibuky zuwwzxaayl rxdsu.
Egam ItkSufocuro.qvazm oqx umw fbu tenbiditt su qri icr ax kjo ac dun jmizq, sertw eshap vakdoyt dzpiwNuonMusndumzak.boyeguge:
Lyed bssha vahw mum qida ijv aqcarv am oKuw ay eJvequ oljj, jek buyj zaba baij oyv leax wexf kubu ah vuwu el u Qov. Xiuym imn xid uca memk jomo, ujd ihuob, ewk i rod imglauh. Fii’gc wau lfaka’c o nixw yuryug maoq adg laof reb:
Key points
Split view controllers make it easy to create an iOS and macOS app from the same codebase.
Popovers on iPadOS and macOS are handled identically.
There is minimal work to make a split view controller look proper on macOS.
Where to go from here?
This chapter got you from an iPhone-only app to a working iPad and macOS app that feels right at home on each platform. You learned what changes you need to make to handle the different platforms, and how much Catalyst will handle for you.
Niu cek keutv lane otiel vla vaxwosolj bokbirpb wina:
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.