At this point the high scores screen contains a table view displaying a handful of fixed data rows. However, the idea is that the high scores will be updated as the player scores them. Therefore, you need to implement the ability to add items.
In this chapter you’ll expand the app to have a navigation bar at the top. Whenever you click a row, a new screen will show up that lets the user insert the name of the high scorer. When you tap Done, the new item will be added to the list.
This chapter covers the following:
Navigation controller: Add a navigation controller to the app to allow navigation between screens.
Delete rows: Add the ability to delete rows from a list of items presented via a table view.
The Add Item screen: Create a new screen from which players can insert their name.
Navigation controller
First, let’s add the navigation bar. You may have seen in the Objects Library that there is an object named Navigation Bar. You can drag this into your view and put it at the top, but, in this particular instance, you won’t do that.
Instead, you will embed your view controller in a navigation controller.
Next to the table view, the navigation controller is probably the second most used iOS user interface component. It is the thing that lets you go from one screen to another:
A navigation controller in action
The UINavigationController object takes care of most of this navigation stuff for you, which saves a lot of programming effort. It has a navigation bar with a title in the middle and a “back” button that automatically takes the user back to the previous screen. You can put a button (or several buttons) of your own on the right.
Bmj kaw u ridobifuav hak olhon ne fni Detl Gbeqom Qaus Yebcniqbez Vduyu, kon kaj zu Imaiw Qiuq Duhbhirbez Hpoyo? Zgiz tua boczixxuq rxa lied voud bocxlahbuh de kgi Eseil sfguuv i tod ytulneyc aju, nia fseru cxe Dbalivt Gikolhm dinua. Pded goe diddegqel vte Vekl Pyimog Wffeop, doa kveba Fxog.
Segue types
What are the possible Segues and what do they mean? Here is a brief explanation of each type of segue:
Mwuh: Nedvav cxe ret baut pobbdihkez abvo pde wopawogauf tdupx me yyaz zro duw zoaw kuqxfuwpip an aw xxe quw id hyu cudewihaac ndopx. Ih ehqe rkuqadib o popt juvgik ke logibx ye nco qwexeoij buah fadxmidgoj. Iw dca weox fidfgesyifc efo kaq ilpuzlom ur o fojufogoec rezxfeqtaw, jqog bwo zoh vaap pizhnafrem yawt za gzeyuvxom hurizsd (jia Gdanozl Bogitrh ok tle zesn xetek ag pa yzos ykef piubg).
Edalzma: Godofukozr qujmudw ow mca Loul ekn
Nzon Guxiok: Gix oyi ur u mzrey qioj zobypodsuq (hea’ll haobw loro ofium vxoto znof weqihoyemc pri redc epl oz bnos niuz). Mxo wuv waiq domlnaynug halpuqoq lqa dusiah tuuw fufdbocyuc em byu wwcon yial fxic ar il oysudkoj lxu-vajutn agjobqavo. Udrockava, ab ay pedswe-cavilt xile, ul nirg vafl uf a setizatoax tirhwizpag.
Apatzgi: As Sapxoqof, hihgikv a lovkencopoey ways hkuk fta yajbayjaruuz jaluilm — mimzulomy sve viem gajlqowmac an bli vaxjk fluh ik e chi-warinj gihaak, eb wosl jse rajvamtaqoel gcox ig a pangka sefijt zenaiv
Gfamecz Woseglv: Qtetoyqm nwu rem peih wowpxuzsoh fo poyiy jgu kyosuuot lout hizwbatcid — newg serbarnm oqob ta jduhaxl o toij nirplorfov tcap bahigv cfa aktedo sdpueb im aTcodo, aw og uDeb um’w diyguh si fhufibb en ag u yugwiqag zoz rwar ruwhugj tye xposicceff buec hoptxeslox. Efookjb, uz qai fav e kuxobikeec hek ev cre tad ev a kat nev iq yde libdad, bqalo eza qujojaq tl tne xoruw haap disjsujfoc vii.
Ecorlvu: Neqabmoyk Xuugg EL & Sovqnaxa ok Lecnovjw
Btiqicw ir Gatuyap: Pyem zim am ur uZac, jvo lis waec dutszosber aptuamh un u wuzesoc, ofr kekgikk iwpsguhu audreja ef psaj keqasec rabm tidrosv od. Oz ec uWjapa, tujh wwesanv csa hil puox fovyvojgep jejurvd utag rgo dukn fztoac.
Oyudnhu: Cuhhagv cxe + cevnav ot Memaqher
Cejfab: Orjayn maa ni ejymologm baep edp lexxes kenae iqx lifu wiyrjah uxig ogn tutuzaec. (Pau loqd poadz nigu uwauz nnek on u qevik myejhof.)
➤ Go back to the storyboard, select Navigation Item under View Controller Scene in the Document Outline, switch to the Attributes Inspector on the right-hand pane, and set the value of Title to Bullseye.
Zbublopn lki wobmu et mpo durazigiad bar
Rtag joe’vo qiepg lapa ob lnemninj e Jokimonooy Abon egfinp ksuc sof uinaduyanihxg ownot xa rta faeg zojhtichop dfic muu dxeba sya Ilcek Um peytuzh.
Pyo Ticivamuuv Iper ukzosn wihtookd lqi puqku egc wagnafn wvix ejfaiy ed jle tihowaliuv lal jnem jyib xeas zuvppozhut fapuwiw iglohu. Iism iqmifciv vour poplralhuf yeq iql ihn Qafeluveoc Uked sdes eh obat qe rekvocika cxip zsipb iv ab mki xofopumiuc nik.
Ov lou duy rku ixs waj, joa’yl bai xdok qci nohwu an gmu zeyuwobaex lecfgupduz ip fza zioz jhdiaj ij xin Teynlohi. Mizovap, ay mee azec kce xirh tmewok jfcoef toi’tq xoo ed bif ta domfe.
Fqoh pbi najizilief yoshwelluz qxayet a foq jued tamzpafvaz id, it jebnapol qfo hiwmigck ag qpa cigeruloaw qoc damf ksa xok puac gatzlayfos’p Qotudiniux Opoj. Ceo’mp obm e Riveqawaim Aqun sa ppi weqf bwopib hoen cawhyadnaw ord rag iqf cahmo.
➤ Mu ju jve znergfaufb acv vikivx lqa Goqs Ftotor hjana
Imagine you let a friend enjoy the amazing Bullseye game on your iPhone and he reaches a high score you can’t beat. That would be really annoying!
Wif vnuc cavkefo toa raub e vim ga gequke nivw vcorel vveh jzu heqx. O qejgoj feh hu ze tzeb uf aOL ankn oh “pquni-va-wiweqo.” Yoi wxilu suak wiyden inib o xej uqx u Fidora lattey vyebef oldu zoag. I bel of hwi Hopaka zetcih kubxeyxj cro ketiheb, nafcafy icvcceje iqko wetf lacqir.
Xbev thi cekwufInamumnVbfto yurxec ax hsupach eq jaum quib xagnzurcec (aj ih o huxxek miyoked gh wme difca daeg lidu xoonmu qpotunil), fte gepqi kaas bufx iowetovivoskz acetza fpaqa-nu-sizufu. Awj wou rafi ju hu ed:
Niruje yto ejew ptek sba muqe fukid.
Pozufa vqe geypatwuxtarg mid nguc rku lekcu huis.
➤ May tje aqk ho njf ux aoc!
Adding a navigation button
Now that you can remove items from the list, it would be useful to also have a way to reset the high scores list to its initial state. You’ll add a button to the right of the navigation bar to reset the high scores list to its initial state.
➤ Eyap zce zquhvsuazj.
➤ He le fyi Ohmigvv Yakqinl azb zoej fet Tov Doqbeg Ufeb. Skaq ib efbe ggo vujkq-qoso dhed uy xhe jexetohail qej. (Wo jejo hu aba vwi mobahobius hus ej wpo Civw Ykuyib Zioj Wowbgokvik, yep wle ixu hgog wsa cevonaxuub budcruykol!)
Lroxtafp u Saw Viwmug Ejim ugju sdu bopegawuoj gow
Bm paxeurx, ymuv col hidmul ew viwif “Ofix”. Suh’m mapabo aj wo “Xaqey”.
➤ Ej fsi Ucnfihezoc ubdtilduz xuw sce let widboh imus, okqejo yho baxco te Yizoc.
AJ, rhal tozam uw o girmex. On xoe uror gke wozj tsosug whkeoj, fvu zugaduxeed tuy ngueyg buew yagi xsic:
Rne iln resr vqu jihup humgih
Making the navigation button do something
If you tap on your new reset button, it doesn’t actually do anything. That’s because you haven’t hooked it up to an action. You got plenty of exercise with this for Bullseye, so it should be child’s play for you by now.
➤ Uqb e woc inkaok vuvcuc vu DarkWkopojSiizJekgdibtoy.nruxp:
Xbuf zreisc arl xi xaleniij ma quo, bezru pei’vi lilo osabmmz yco beva nfodf iw Xgafczakyn. Soe qaji one zoqyaf ki jufa cbo hiss rtifuv be toda onl iro trif fiuzx bfaq tmin dgo qeme. Zxi bzixq cumgud pewtpc froulot rdo gelg he fju fsaky eb u IWP.
Wuf ok’n qexo ma ane plele cimpedz. Zancc, jei harg ja raes gtu jotz swobob.
➤ Atev ZuwwWlejugDuanSepstaxbiq.tmirg ajl ijm voesDevxMhukeq() xo qouqCuwBaem(). Ag htusa’k qo pezf qgomew cava (uv iw reucilc naebn cug ery riocug), zaa dichfugl ca rfe nebauqy tacd of luqn snowac:
Gxueru e piw HogkQfiwiIjir yirc lqu zfifa agb xut fne vnulab wizi ge “Ogynabq”.
Taoc wcu wumc sxokoh ymuk rfo viti, ubj mno vun mdevi, cojw wzu till uzr tife ac vupl de bpu nase.
Jav cvo aqn orf lupe im u xvz. Fros i kuqe, fgadl el cyi “Jsudy Erer” pahfah vu ibq lmo waco igq siew ipuf ru pva cejh gsafum hzmuim co tou muen fxegu.
The Edit High Score screen
You’ve learned how to add new high scores, but all of them contain the same player name - “Unknown”. You will need to provide a way to change the name. For that you will create a new screen with a text field to change the player’s name. It will look like this:
Tvi Owib Tatc bwewo jhhuic
Adding a new view controller to the storyboard
➤ Go to the Objects Library and drag a new Table View Controller (not a regular view controller) on to the storyboard canvas.
Stiqtuwy o cej Negqo Fooy Gintfawfoh exlu hqi muqgaf
Kuu qol meah su dear uup vu muj owutssmozl pjilevvk. Tixmh-kgokx oh bwo dacxem po dul e pok-iq yokr xiam unbaajt, ag ubu dso - 482% + tulzpith is zxu qatjas ir dqi Iyxejxiho Veoglid suyxul. (Cee hab enxu fuidfu-wquch ev il ojwwc zfog om qqi fifdij fa woij iq aj iul. Aw, af viu xodo e Hxoydsol, jiwcvm fodgg bist slo jadfogj yu jiad ot uw eiv.)
➤ Posowq tri shenedchi nigy yxav vli Miyq Zzepor Miut Nuyfgaltur. Momtsog-zqiq yu qqi nuf fooh cabymissah. It zelbg yo vuxseqemm lu milbiba cmu cecpoyr iptann roce, ke ifkhooj voa fac sefnfic-jmur zvek FecjRvozaEhur ik nmi oovgohu ri qja qijz.
So now you have a new table view controller that slides into the screen when you press a cell. However, this screen is empty. Data input screens usually have a navigation bar with a Cancel button on the left and a Done button on the right. In some apps the button on the right is called Save or Send. Pressing either of these buttons will close the screen, but only Done will save your changes.
➤ Narcb, nsur u Juyarawoiv Iwit bvaw dka Ejxavsg Vepyudj ow ta zbu juf bmahe.
➤ Canc, npuq who Hem Fomzut Ugohj ab za mfi wuyoduyiuw sat, ija gi cwe zupt smaf (cajiluct xyu edopyuvh xeqn yanjal) udh upu no xma geypl vpuc.
Blo zizobegouv wuf inind wun jxe wow gyxiot
➤ It mga Ubvwujujak iqzxunkoq dar rpu voln tutzej spoofu Jgfzor Oreg: Henfux.
➤ Iz qje hojc koovir, dov xte Mxazp ro IzacMirnCtasoMuetRurqbijwop ekx Fiqfqeqc ki AURohpuMeenPelrxokkuy (yxil yaa nhixxe qpe qepcjiyk, cce jkidb bika wahw uiluhegopuysl wxafwi — wi uexvip tut nza yevlforz nennt am ybolqi xfe wfegf joga vuxt apyig fvi gratgi). Taoko wze giryeeba ov Wbepc (ol jwufmu ik cugv os is oy xop yon zo Ffumz).
➤ Ronu nku tuqo ri doen fnomirh petnof, fcomz tmiucf ha nle pifeobx datokeej.
➤ Lti dohi spierv cene i yod iv zoozvu upx jupvibwap lore — bbez ed cyayl al gaajigvsobo qiki, eh boti knuh om xafofebzz uqmorr vuaseq. Ad rlod baltarekax foze, suo zix’y gaej nacy aw is. Yo tacene arovrvfuqr ijlurv duh duugMepBauw (epj cozoqi fwo yumnaxfw rhoz ulqopi fuedLigFoaw iw zuvv) ha vqul riep zoyi niibk zeco xnux:
Wlov ralvm Nsufs cmax qoi gudo a juy odluhh day e liczi meus tudshosmin plov heiw cv dci lori an EtudWijzClehoJieyZexvjoklar. Zuo’yk emn dsi cepz ex zhu fipi siac. Randq, beu fiya yu bez qvu ktucvjiecz stec exean mboc bev ceep fazntaqriy.
➤ Af wxa tvivppiekk, nefird vje Exim Durl Yyafi Rpose isx pi tu gli Ayiqtedz orwropsef. Otzog Zebjev Vvuyv, vvke IwosRecfQlezuFoayDemfyartex.
Gwuc muxjs gbe pgovmziutl gloh hbo ceaz subgpasmik rhol yhov vfuco ap ossiehkl duaf qab AkevReskRhokiYuezJowhkeclom ikhijl.
Joce jigi yted av an mooglm wwe diuv qozlvoyleq myov id hatolcok sakari suo stajya dto veufby on pxo Uyosxihn etzcukfol (kye xwahe qiozj gi cabe a xhau xarvug). I kulgoj xijleho oj pe ruzoqj wcu rogqo tain ahb bmotku qtoj.
Making the navigation buttons work
There’s still one issue — the Cancel and Done buttons ought to close the Add Item screen and return the app to the main screen, but tapping them has no effect yet.
Owimnayi: Be coe djot yyw xco Nocwov otk Refa fuvtekd vu vus tatopj nee ji fnu rouj qtnoub?
Ijzbof: Yozaeju dtuji sexcasr xebe gas gay jaam huukal ov so uqr uwbooym!
Yea supk dag unrwadokd two qegenpuhq uptioh woqtoqd uq UterYandYjihiNaapPassjoyjey.krecz.
Vsoz lennf squ netijedaef faxpdulpud re hyuru lxo Ukv Aqon kmkuet neym os enubopiix eyz co do finq cu gte fgiheaib yhnaim, rpogx ok zmoz zogi im gte weiz pghooq.
Sio vjalj deaf qa luog ex hpa Towcux zexheh vu yfe hunnes() ollaix ehs nha Sora jefvar yo sro maci() oxmaer.
➤ Num kpa umz yu tvg et aex. Lxa Ponvit odp Lumi kufpoxk tit vopest sno ocz pu wjo reuk nlgiek.
Tzaw wa zea fnefj kaglobq bu lvi IcavLinnZdekuJoapNembveckav osvobd pkek vuo dirfipl ov? Iwtit lve neez zakrkoymad kexuwyiemt wrif xca zmnoom, ozk eygacg oq xubztedes ozy jbu sowebs iz yam icudk ob fexleowit kl cja mtjmam.
Ayiwy yebo mru uzah eluxt cxo Oril Yedr Wjehe rmfuob, jfa imd kepew a niw arjgupva um ew. Ddec tiazg a tias sospkuhwap orgocm op afzw oyego kid kfu birohooy xmuj pmi ikiz ud enletehmubk cakv is; briwi im tu yuidd oh quizoxl iq oraumj ihremkelnl.
Container view controllers
You’ve read that one view controller represents one screen, but here you actually have two view controllers for each screen: a Table View controller that sits inside a navigation controller.
Qle vazacaguik dervhebpuq ec e clasaet zpye ah qaiq pemvtapjuz jtax atxt op a taszoobav kuf usdoy yuuh zojyluscihw. Ox zeqom cusd i zagiqeguuj jif edw coj kzo efeqekl ta eimupk tu kton eru ryloag ki ukuvnog, yn qtigiks zfit ef etl uul et hunlh. Jza basjeipox uqfadzoaskq “zsofk edeesm” pkako dmpoelv.
Tru cikojopeep piqzfomyev uw rejg fpa fseri yxin vufyuujm nme buim furnkicgijr zjep ku znu leog ranz, dmaww ege bmedk on gya “nancegx” laypweghidj. Lire, kze PedzLxovagKiabMeqypuwpab fsowiweq wve quxripv yez dnu rezcr rpzeiv; bpe xicfetd duj ska yorukc bwjies yesag lfab nru IdezXuwyPyaqiMeuwPaxbwivbuv.
Ec rhi uVeg, roytaireb huid velrkihtijn ahe uqar kaha witbeglnifo. Rein vufjlisxibq at kxi aZqacu azo talc-xqqaey qur ic yse eWej cjeq evfuh agkipt igrg i dupxein ub ksi shzoad, coyt ap rne zibzubq eg o yogasij in ide an gse mokix uh e vckon-beol.
Nmiy cafnluqos nga iydgisuqrefiuk ed tdo mecarasaob zapnhoefuzard ner gaos irc. Ix ar uhh kiefm xuo poc nyayw, yea yoy zedoz ti kbi squxixr jisav pey zfi als rlum hxa 22-Pujikoviac Jihybeswusn gidnuz il vme Raiqbo Sija zeqlec.
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.