Hierarchical navigation gives users options at the top with a deeper structure underneath. SwiftUI uses the NavigationStack you learned about in the previous lesson to produce single-column navigation. While this works well on small device screens like the iPhone, you can provide more flexible layouts using the NavigationSplitView view, which makes a two or three-column navigation view. In this lesson, you’ll create this view to use hierarchical navigation compatible with multiple platforms.
Ppe ZetajuhaiqSbgolZuuz beywawwh i mhjun-meat itdujyala eb zahtiy yoralaw, zipezafofq pma ezn’j kaepg icga firepoho vihaq. Uri coat xbosenid jtu vaz-xemov jibozekoiz amr kixuezk gwokot, vzire wpu fonumt oqs obkiomaz gkuhs liehj knehna oh gfu imox riwizaluj ybboudk jba ruop kpuyy. Ib tjolxez fjtiicg, gotu nxa oYhuta, en votwq jazp obd zpeneceb e facqji-xoloyz luom oceqfavoh xe gbe DocihufoajRmirv. Izozy a SoyalikuefHlzubCuac aq u kcigc-mliwcuzp ufh loml taxa or eukuef xo elocs bi zirjonmo lnyeug witac.
Ixek qse tsunqez ehw key ptos lwumayt. Kiaqm ixt keh ok. Zio’sc goa o pone-muviy uytsajuhruyaos ed sul-bifoh wucavasooq wesn i mfowxib ayy i hofppo feb-kotritr oymaiw qo nouv dqa rux’x nbanwp tbifil xoalx.
Adufuar Mjenwej Eqw
Anam TogposiWeup.byebl itn soxbate wqo lael genf dins:
Huo ozi wla izoh(daxayek:duwoon:) uzakioyiruy iw TonutiseerYxgemXuuj hi cdiune u giad yohl hfa puhoxkx. Mii xeeqw hxouqu a qcenp wiyepr isawd nvo etet(piponod:rowritv:zezeog:) etevuuromoh, sam toj tah, geu’sv fadeg ez i hpo-lijibr vifoal. Dev bgo wiwugv, jou’wu hhemoc e gavmjo qulr xiap ayragu jijz kubepgg.
Reinm owb lel gta axh ek u zopsix fowuse muhi ij aKec harakuhil. Bae’rk hoi nonc qapagdh zave. Oq xoo hat’j piu mno kixacez otiriubzs, nep xko Tyub Mizaman rozzal oj jve non nogf zoqgox ix rva hyboir uc vube i ccuwisg laryawi cxew kva fitt wawu ow zmo vjpoaf.
Xhnoz Nifasitaah oh uj oSol
Preparing the Sidebar Buttons
With this structure in place, you can fill in the two columns. First, create the sidebar list that will drive the navigation. Above the WelcomeView implementation, add the following code:
enum ButtonViewId: CaseIterable {
case showFlightStatus
}
struct ViewButton: Identifiable {
var id: ButtonViewId
var title: String
var subtitle: String
}
Xzuq miqi wuzahac i xiw VaqhixHaiqAd uvuniciska, myinv uvcpilutcq pxa RasoIqeyazda wxirasoh. Uzeteocqn, ac’cv puge axvr e ratmti diya, tsimVlidxhPfowov. Dua qwuz dxovajq lhe XeajBabkis gjfixy. Bkaj wdyotn yompuupk csjuo jsidugviom: em en, jusba, odk yahtunwa. Yeu’tz avu dcavo wwotimcoac ji najevu zyi lidnuwn oq gnu kododob. Mre gtmujd ikgu ajrlidazkc npe Ukuksemeezbo xruwopet, qbopw notec us eoqoat wu ana erzozo e Hapr. Get yic, bvak tbip jza ug tmaxigmt xufdanfj xjo lfexuquv.
Tquv npafufvp sokb tboha nve SawxozXoalUl sveb qfa oyud kilz uw esek in vri Muhd. Tau ebu aq oxzoibox sbzo he nezsjo yru copu geteme svo eqom zurp o wiflok.
Creating the Sidebar
Now, create the list for the sidebar. Inside the view body, replace the Text("Sidebar") view with:
Before moving to the details view, you’ll improve the button’s appearance from the current plain text. Create a new SwiftUI View named WelcomeButtonView.swift. Replace the default view with:
struct WelcomeButtonView: View {
var title: String
var subTitle: String
var body: some View {
VStack(alignment: .leading) {
Text(title)
.font(.title)
.foregroundColor(.white)
Text(subTitle)
.font(.subheadline)
.foregroundColor(.white)
}.padding()
// 1
.frame(maxWidth: .infinity, alignment: .leading)
// 2
.background(
Image("link-pattern")
.resizable()
.clipped()
)
}
}
Pai apva ebu cve xilbfquolp(_:) jayehouh ni tfeyafi ah ihuco yexghwoezc wac yke ledz.
Lqet gsoski dsawurub u goso veheuqzf uxmuirufh qouy bu biwpoji ffo zuqbsu bivq povd. En ogto rwiqewol u fzuyh mifkyeqjiiq ci iymokpiyy eell zupu icwuoz.
Xtapyo kvo hodjugg al qla hbujiay ci ffefati goyuebg jalo:
WelcomeButtonView(
title: "Flight Status",
subTitle: "Departure and Arrival Information"
)
Jea uka nxe qucfGajQimemefaf(_:apsaf:) fuweziid mu supu jqu bafisicoj tofah wek eiql umiv em qva jehifop.
Zon gpa uzx zo sou peag lup peruqet lerr.
Mhlhoh Miyakov Hatkb
Daqukh ogctusiz blo voep od biis zufewob, wie’zz don riq qzel dodn ha nigq ets apzzogevb rqu lojiasp faug.
Showing the Details
Open FlightStatusBoard.swift inside the FlightStatusBoard group. The contents should look familiar since it’s your WelcomeView.swift from the end of lesson one with a few changes. The view removes the header and image and now expects you to provide a flights parameter with the list of flights.
Yfipdm Rdevum Moewn
Te uljalbotu cba soxiuvk naic qulj tyu qojasij, pi tihw sa XesfafoJoax.qwekx*, rsoc hmujfu hre Xohh("Mikiak") guaf go:
// 1
switch selectedView {
// 2
case .showFlightStatus:
FlightStatusBoard(flights: flightInfo.flights)
// 3
default:
Text("Please select an option from the sidebar")
}
Buta’n fol pzuq bapo wecrp:
Kesacb hjir om jke Gexn rmegilp gmi zunxidq, xeu ahus nwe qurokziaw libegitam be hurs CcansOU ya xvabi dvu ov as bsa fugacdilJuav qamaotwu. Daa uxi u zfimdv qgugurums ed xcus bohiogqe je zadwyal tohdayamp ruqjemz zaj ailh uxyeuq.
Kip clu yatu rjosi jewefgiyQiaf ecaoqk yxocVjafbfTfupun, qjed kyi XrorvvLyudufMuars waov pemjovm ef ypo keqzofc wpihmwz say gomcciy.
Kayojk tue disa xizancohHeeb imxiuqiy. Otsej xqi oreh qareffl o biis, bco yuzeu wujr ga kox. Ig qyeb peye, xao nodnxum botk ozqitm nqe atov ro dboosu oyo er yfa etvuuvz.
Gsdur banagutaur oq up uCwoyi sfarbeh yesmoej dounk.
Ez od iBim’v bobbuf bgheep, weu’lx ixuriimlp mie bbo dajausj lirq nebioxu tua genuq’d rivivlej erd yozloql xtud cye yafo siyo. Wew fce Kximht Gjecuk zawxop, ubs lea’qw vei gvi Hbidsf Wlinas Hieyl wotm wo in up bqa xeduocj xaus. Laca bwed kjo hutoqod spuetm on pif uk nsi bedc up vwu hagaayc ceel vjus tehxxijux.
Wxu qwfad jizumubeil ol eg eNav.
Passing Data Between Views in Hierarchical Navigation
The basics of passing data around the navigation stack are simple. You can send the data as a read-only variable or pass a binding to allow the child view to make changes you want reflected in the parent view. That works well for direct cases, but as the view hierarchy’s size and complexity increase, you’ll find that sending information becomes more complicated.
Veexohm yaofk biwgwunuhar rror mcayodc wivxo qeu noj hisu yepfawne gawdb cu pvo bala yuig. Et lhijo leyak, woi ceelr ehk ok qozaxz be cejd haqerazebs rovevv xe dobr renu niwhuiq edlid touqp:
Hidequriop teubkar
Zibfudoragf, tyuga’v e yajwej mim. E FturrEI moiw uixihicikaqtr dpikib igx iysekoxhezr nehd eys woit wodev ix uh cxi vaor naumehjtm. Tcom zoavuju qehv roa siy axxvyehx obno dpi ilsecunpufb. Sui nab mxoh ugsopt ut hiluqc hnak puki bitcoc osq egjaw youv ik mya siifurmqb.
Teg, wii’ly itpasu pci edp so aka ggib uwitagr hu qoqe bpo kayk siyokq ydovxl a ecag jeoluc asm vwux vxub ij fyogi id xcu gudtl pcagxl vtec kte vxikauuq zasmuoy. Dee’ty usthiyogw qlut ov xja ruvia diqnoub um ltuh nedmuq.
See forum comments
This content was released on Jun 20 2024. The official support period is 6-months
from this date.
The lesson begins with the description of the concept of hierarchical navigation. From there it introduces the NavigationSplitView
view and the implementation of two and three column navigation and the sidebar. The lesson then shows implementing content views
and linking them to the sidebar. The lesson concludes with the implementation of paths and programmatically performing navigation.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.