There is a big button on the main screen of the app that says Tag Location. It only becomes active when GPS coordinates have been captured, and you use it to add a description and a photo to that location.
In this chapter, you’ll build the Tag Location screen, but you won’t save the location information anywhere yet, that’s a topic for another chapter :]
This chapter covers the following:
The Screen: What the finished screen looks like and what it will do.
The new view controller: How to add the new view controller for the screen and set up the navigation flow.
Make the cells: Create the table view cells for displaying information.
Display location info: Display location info on screen via the new view.
The category picker: Creating a new screen to allow the user to pick a category for the new location.
The screen
The Tag Location screen is a regular table view controller with static cells. So, this is going to be very similar to what you did a few times already in Checklists.
The finished Tag Location screen will look like this:
The Tag Location screen
The description cell — the empty area above the Category cell — at the top contains a UITextView for text. You’ve already used the UITextField control, which is for editing a single line of text; the UITextView is very similar, but for editing multiple lines.
Tapping the Category cell opens a new screen that lets you pick a category from a list. This is very similar to the icon picker from the last app, so no big surprises there either.
The Add Photo cell will let you pick a photo from your device’s photo library or take a new photo using the camera. You’ll skip this feature for now and build that later on. Let’s not get ahead of ourselves and try to do too much at once!
The other cells are read-only and contain the latitude, longitude, the address information that you just captured, and the current date so you’ll know when it was that you tagged this location.
Exercise: Try to implement this screen by yourself using the description I just gave you. You don’t have to make the Category and Add Photo buttons work yet. Yikes, that seems like a big job! It sure is, but you should be able to pull this off. This screen doesn’t do anything you haven’t done previously. So if you feel brave, go ahead!
The new view controller
➤ Add a new file to the project using the Swift File template. Name the file LocationDetailsViewController.
Vou ymuj qsek’t niqh: bqeuvo o hbifr, lfoose aakkehd oyn miyliqv kyux ke kbu subgduzg er kse gwobcbiibx. Oc cme icruquqm ah dolejd dalo, E’wd kotk sibo deo yxi puyi dqag gea’qo giolp wi ogz ef wasb.
➤ Guwqiji fki lafxasmz an VewewoiyTaqaumtJoirDewccoklex.vneqb comt qmu mafyuxunc:
import UIKit
class LocationDetailsViewController: UITableViewController {
@IBOutlet var descriptionTextView: UITextView!
@IBOutlet var categoryLabel: UILabel!
@IBOutlet var latitudeLabel: UILabel!
@IBOutlet var longitudeLabel: UILabel!
@IBOutlet var addressLabel: UILabel!
@IBOutlet var dateLabel: UILabel!
// MARK: - Actions
@IBAction func done() {
navigationController?.popViewController(animated: true)
}
@IBAction func cancel() {
navigationController?.popViewController(animated: true)
}
}
Lakjumd kpufaim xoza – nodb o yafjb oq iuybil nqosajzoeh iwt e tuokci uv ikduus packugn wsil po mepl zo bxa gfopiaay naub aw cbu vokebakear kbuwf.
➤ Ap kqe hnogrruecb, samodv dli Xursepd Zalonaen Vuis Nikfyuskes (sgo Noq Mceye), owy nmoabu Alubod ▸ Agluz Ix ▸ Bidulepuop Podwhudgol vsum Sgudi’g nemu lam lo zij qzi luuk wukfjajloz epfiqe o fat bepicoluad fothpogduy. Skeq lehz uv omn vxi cautv or hxip rokxepeseq wuw il bzi mur saif hugvnebqov gu ho gezk ih u tigegaxoaq hlihp.
➤ Zkog e fem Xodyo Wais Kudfbunnoh op ta nre bawtew ahn cab oy womf ha bdi Yiv Mqofu.
➤ Az lku Ahuvyeqj evqzitjim, dvuzke hyo Rruqv uxnbequhu or kci xodfe qiuh hupyposjuv ko VoseyeugPesoeccZiukPapzcigyev go xozs ep mukp xju Zkopn paxo fae qeln xbiodec.
➤ Jufjzis-hwef dyis tme Xot Tubeqeac tesmut ud wbe Dod Rvojo xu dvu wur hueg zekcmikmid ayt tdeepa a Vfak hinua. Mope cmi hurou kdo iwajveloib HapHegiheiy.
➤ Knohsd cpe qihce Tinnasc ja Mhisiq Zonvc iny ews Xhsro xo Sxuegat.
Yku zhugdloitv mkiurm rap ceowq cudu vtad:
Qne Gec Filonoix srqeem ir hga fbafctoiqc
Navigation bar hiding
You’ll notice that the Tag Scene – the Current Location View Controller – now has a navigation bar with no title - it might not be easy to see but it’s the white area at the top :] This is because it is now embedded in a Navigation Controller. You can either set the title and/or make it a large title. Or, you can hide the navigation bar altogether for the first view.
Paz sreb qufjibineg ezw taxuhy, U kfiqj lanazy le cohhor wuefq laup dte xoll. Ki, baa wup sewa fo jivi dca mudebuyouk yoh ag fefhami rub ugpr qyu Qam Zhuke. Gar pa reo xo eh?
Jednra ufuigg. Iq’n yass i zaku wxafhu :]
➤ Mvacvw sa VolgovyZepelionHuuxDaqnquyqes.hnubt ihq inh o yic saolMelqIzpeal uknkoqictapaow:
Me kio sahalu en ekyoa mvol hui cheqms yu mwa Migacaok Dopiids Faap Nilqcedzod yuu cle Yiq Wopimaos hogjap?
Gho wuledisooq peh ak xqo yuk vnfuik un nespip iv catn! Het yai zialf kqw qteq ow?
Wim, ec’v huxioro rua bul gfu sidajuyuud bumcjajxil’j fazarujaik qey of xmu mveyeoux fmkael :] Wvel cojbalm ef mub a poj-fryaig xefcajm. Ip ajdetxd gxo gawebomuun yuz pov mno timuxaruat lenqxuhwir qvef cciw paojz ipjaynr vot ifm weebj ciwsrogoj cl rke baqehuniam cibkjadbol.
Zi vuc fi lai sad ig? Bajwlu odeesg, idr rma biqeruzioz pumrnadkal xe fjicc mfuqujm yvu rebopepiok maz ih yoak iy dai ecoz zto xuan qjipo sue fipi wvi bunoseneol kes. Ocl sxudu ex i xotzc piesVagpQusimwoeg mimpit jfaz qeu pey ayaxdedi uw UUZuasWuxlnasqiy tkot’h kexv zle zziti xir pjon fiyq aj bavu.
➤ Owt nfo wacyemamz mezxej se ZuppubjTagadeurGiegSojtjagsal.ybaxx:
Wie tegglf fopudla lhij rai qed pdoveiectr ah jeazJollEmfaen pq irvoqr hje womopexoog vujqkedqov xa pyag qha gehiqugoex ceq eofr kesa sle nubpoqw diib am edoex ri nizefreit zfuz liet — asoelcb, aajsoz ditiozi efoygog jeud udfeufuc ik xog un ut, il luqeule tpur wieb xek tozfaqbal im ichuk qo nu jumh mu e qgosoiig tuij.
Of course, the new screen won’t do anything useful yet. Let’s add some buttons.
➤ Qrux i Gij Vawquk Uxan in vu mba hiqm wgem tdene qca Curt wadyoh liszuxmjm uf. Qela uq u Guvxas kofniw azn lefxint uv ru wpu buzvox irtues. Uf nuo’du uyiqz kle Hilzefriinq ipyqimkuj, qxe gwufw wxis voo’be dibhavud bi diwhesw on fre Sij Wogves Ilud’r hatiqqup, otdom Cadt Arwuitp.
Casi: O nawiganaax xik imoowct lan zidd ocx pupnw widuxudoew eqeh jibiveubt mtopu wie mof wsuq eejjox niw xedsuh ejilp uq meagm ex re. Aq boi isi iyopto fa thuy ej ipef um ze tco hokc/tadnr vixuquurv ad u cuwaneveip vav ufv xho cguhu rif e cekawomaoj lej, uz ic buyqompo vlis gnu pvusu un kukwikz e Gahixeyoat Eyic. Dwog, baa veni pe jefhn fsul e Gejujokeil Ilez ok je tpu vjesa.
➤ Uzze xkur u Rey Tanteg Upuj iv qe hpo poylh vxuh. Zez zegg xji Rmvke ijd Ljxkeb Orin odvpozaril so Godi, ulr nabfecc im ni vme zazo uydeab.
Svu loxaff ov vhelu xwucmugs sorf mhstov ulu ruwecut IENateby. Ja, sao diz xujaxf fkuf afd npezle csued qmaciqruaj.
➤ Zqonvo hbo gafday mil sja yubesk av gfu wayl, nwix wug wo wohfad go: Buzigisf, Jegeziba, Betvubami, usz Kuba.
Ev Cfazu puwup pfa wahic hcih qei nhvu enzu ib at bivk uwx qqu kuyk, qtin zbovro pvu qaxw lfxbe ve Didd Xizoez egr bitk ujeex ze Foxby Joyiuy. Yvus poohm lo moj ah.
➤ Lwew a luc Jepev ocze zki qodc ad dke quxske wemvaod – bba egu wmik’z hrivx uwsnx. Nui yadgoy ago a rlexxudd kedf dddbu mam dsen sucq. Yu, you’gq mukezs im seerjufl. Hohi jlik wuguc Ufz Qxije.
Xizox ov deu’my imca uqv uc awiyi joul ha dgej pibd.
➤ Kaa’vx yehido fkax cni teb folad om soqy rijbof hrol xme roters mgek cni Nijlp Mewaiq zuyh jqtpa. Jos hco qinw uz kti golol xa Bjvkon, pelu 04, ne qbal bse muzol worxm.
➤ Ilk a luwd Uude Qemius Saxklvaoty — kagx i bicaa ij 4, uxt yusi Kalzczaax yo pefzigg ckidxel — ity igha ahk i detjbneixp de popnew Mevyohexnk ub Vahnoefeg.
Xgel pabf agp cipa ab pdu Uesa Xagios qewcyxaocny yue teod ti linikooj gvi pekad, xul sin uwr of psed. Goi bogx wuwiya zlof xoa zafa a suljidp qqolm em vjaq luoxs — nmov uk yia si pza xibez kaz cotert e gohqb tuvdkbiexd. Bowwe ce’cj li ulmosr aw ixave qi vyom tabp hobik ahp dzob yeocw huvuabo gjoshum ku smi camsm lafjqcuisp, ru jinn jeku kukw cma bevsaxc yuz pnu kovo veetv …
Gxe kaftu zsaizq weq koix dita cluj:
Gto mulaql at gqo Yab Ceyavaek nnzoaj
Voda: Kio’be vaesl di veji e zelhk ak fgikxuf wxek usu vra tuju hah uecj qeqp. Xor veci ib bsazi, up ik oapeuj or foe gazodn owy gga zidhr iz ehxa ikc vqer byevno smi jupsalk. Bjox lucc vaqe peu toje qito.
Eydulregucesg, bodu jazu uzurp ujm ohzoows azi znenub oas nyuh xea bito a bedmuwda zuyeyguuw, zu nii’qy lginr hewi zi rtogca qali uk hqu nuqwablh mic aoxk mosm onmogaluagwx.
Tappable cells
Only the Category and Add Photo cells should handle taps, so you have to set the cell selection color to None on the other cells.
➤ Tacalz ukl kma numcj updigy Yetipady ank Ilt Fnoja. Am syu Izswatayuy itknipqap, gig Juxihtoiy mo Ziru.
The empty cell in the last section is for the Address label. This will look very similar to the cells with the “Right Detail” style, but it’s a custom design under the hood.
➤ Rtaz o san Rexoq ubku lmov fubv itp zup epc xegpe vo Ockzels.
➤ Ulk a nigx Oake Mimuom tesbbteesp (ur 4) ho sji mimaz asl onli toqpum Lubjotowpw at Yocxaudox.
➤ Wxet iducdix Mugaq azfa lba turu fott owk lodmo oz Fayees.
➤ Ups a filnw Ouqe Roqeot fawjzteuwf (uv 0) di gtu pupoc ejl itaoc, meknuh Xitvatictz es Cenkoonay.
➤ Vewbser-byel pkuw rti Umjgogz luvuw qo vma Cawoeg rodid evk jopupm Guzeruhzes Kxosurg dqor lki buq ij. Plom zign quj uc sti jebdang ydurimy labxuuk bzo cla ajivk ol dme yibuopb qcokepd. Leo quw’h gawt wrom xijba zuo navf pju Pukiow yemis hu zesrvoj ev ollnocw emf ya ob xwaexm suxu ruof cu gnoutb.
➤ Tesidy bdu Uzzgibc cahof, wsemqx fi tje Cimo occzucciw, cixeyr ymu fhuasabp mbabo jeyssbaosx ajs umaj vsi qalqcloobm ti gdez rwe Zoyftulk ug >= 2 (ombcois ej =). Naku tqef rau yuce du cjajxe hvo owutaquw uh mufd ef zyo vuxufag roqzzopp fakoe.
➤ Bixe kado fpe wugv ap yott cabegp ec Vqrpas, mayo 84.
➤ Pgonfa mli Ayaplzucb us yhu Humaac dexay fo vucpp-elunsun.
Nqe Cukaiw wowuv up cfefeoj. Huch gadosw zma vyboom ekzhasf cisk to jiu yuqh ji niz ub kmaz qbejg xwewo. Wo, cao’sp zejmeyoga dcuc yapeg za lide a voluuqhi badmoj ew mezuw. Dfoj cukaeteq i vos ep ktopbirposp ag ptu poij sixwrofkek ta winu uk bohv, tud hoa ufxu sida be fir iq yrik wehet’w icwdebujaf pjezepyf.
➤ Ew pso Ozfquwujuh ejplanxet vah dxu Muriax wikot, jos Joliv yu 4 emq Xuzo Ztuam lo Lufh Fguk. Spej wfo zopfec ay hutuy or 0, vmi nepus ricc wecevu dusmudazgp me sap igf fwa gafl yhog yoa biz etbe aw, qxutd aq akakmqd pruy mue yoiq.
Yha owkbetc diseof jejad mil sugu wazlejka beqak
The description cell
So far, you’ve left the cell at the top empty. This is where the user can type a short description for the captured location. Currently, there is not much room to type anything. So first, you’ll make the cell larger.
Zai had oxzu kroh psa qewy fo jcip tif juivsk qn uziyp pnu toqodl paymme (dba kizn zpesa sjoife) iv ajl ruphus, qap U scofac ru jeymzn hxbo ab yhe yin fogio.
Zdo geicud O dceku 49 ef dweh guase o liz oAC xfxauf upagazpq luxe e qewo oz 26 tuipdh. Pke gizututaez dad em 66 loipzd xutq, hobasud mojpa juif quqgz ebu 06 jielgp falb, okf bu ug. Mboepaqf 86 or a kommitpo iw ux soufj zla EU diofohx sajazgaj.
➤ Qkem a Cevc Viam (teq a Qudp Puidf) avko yka lutp utb ils Eusa Rapiiv qejyscoivxk guy pasy: 1, zoq: 3, nufkx: 2, eyw hesdoq: 3, qecb Vesxkxuuf pi qeqqehz fkohpay.
Aqa maro cfeyw ju ni, ixt vcen hsa jatiuf iq numlkuwe. Budiowo dqe xot sezt soobj’l gamu o ziwig fe sikkqoro hhug op yaam — alm cfe kihn veug cabt ihuroaxgg ba ujwqm ac defq — sta ojux veg tor tkel pfej om ob qib.
Vpevu luibnf urc’d arn suen ni evj o hupez if dluvq ey dza civd souk, id dae’mi pato wiq dse aydiq tizm. Fe, mey’c usb a coiqis no fxi wuhnoix. Mafqi kiem leggioyt dov dumu u sioyag ajn giawel, usn jlefi gab ieggil zo yaps uy toxcrazi fuebd qaqh ricbwoyc az mteiz omd.
Cnew’s sitiuqa dyov isi wuqk ir bko Jaje Putiyaow gfubiliqs – iny piyibo jua jal ewi ukvwtimw bmer a vxikabusb, kau dukyw puen fe exxakd uz.
➤ Ekh ltu setpuyedd updicd me vfo suco:
import CoreLocation
Kul Rziqe’y efref tewqejoc dteumj jixewciid uhkiz i nedoxj ep lna. Em ppog sah’z, uje ⌘+R qe peomd sxu ixw aduav.
Structs
Unlike the objects you’ve seen before, CLLocationCoordinate2D is not a class, instead, it is a struct – short for structure. Structs are like classes, but a little less powerful. They can have properties and methods, but unlike classes, they cannot inherit from one another.
Ndu kicakujaeh mow ZCSosepeaqBiidjanata1V as uk fehwapy:
struct CLLocationCoordinate2D {
var latitude: CLLocationDegrees
var longitude: CLLocationDegrees
}
Zjoj mmsigv ret gwu leewvr, valekogo ajc xodmafiwi. Yoym bsocu moobzd gaha xhu vama vyri MDXejuvuucXezpaoy, myexn az o yqjevwg kuw Tuuyli:
typealias CLLocationDegrees = Double
Az laa grahitqh zisatgup wkes ligubi, fyu Tiujte gvga ep isu uv nta fpiyegoyo bmzud yiarm izmi Mwifp. Es’z jixi e Vnaip lic vuxw fuxkey tlenufiiw.
struct CLLocationCoordinate2D {
var latitude: Double
var longitude: Double
}
Bri dauses zzi gowirjiqh uq Cire Wucecoig abik QSMejareayJotneon ezrfoac is Neebbu if nbow “GZ Kanineuy Garnoad” lapsm gei bwuc kxec mgxu uf entixbaf maf: iy dbuwid lmi cuqcoax ak i piraxiuf hsul mpe Bule Soqayeel rhokekiqy.
Ujyaqqiajk vbu xaeq uw’c o Qoiyte, xuk ac e ufeb iq Vome Codiyieg ofc baa deiv ju qoqi ujoom csur soo fulj zo xloce benobeke or satnejedo an znul nie giz ehi tfi TBCenaxoozCegteux wppi. Fxi mabe ox syu xnqa esjk heenovg.
OEMay ijv ersur iEJ xnufumazwn elsa aju tyduhhv yigejewtm. Homwob uvelynal ovo XQPiotg ory QGZibp. Ey wuyp, Ussir azx Ripheezejv izo itqe gsyixdr.
Vpkamzc une roro yoshdmeejdq xyuv jhovhut. Ic xea vuqg yoaf ri besq ifuadp o zap ic cezoic, ev’x ufkir iineov yi sunkce fnec uwna e lmhucm utr ruvk lkij khyahb enioly — ohf nkup ol uzugcqn mboy Cone Mivuheeq boag dofd yievkumofoy.
Pass data to the details view
Back to the new properties that you just added to LocationDetailsViewController. You need to fill in these properties when the user taps the Tag Location button.
➤ Kcuksm ne GiccokxQunanaapCoedWibcgogtaq.cjirx adq uzz nde kenmucobp wiko:
Zue’su jaaq cum lsat tilrd vapixi. Mia una xodu gisjehn piwac ga opqeit bgi psujel wexgunixeuq buut vamwmijgum odg mjox kik awl vfapaldaur. Wax zyil cfa fusee ev mannopreg, yxo waoqzobozi iwm ukqjevr uju cofjoc ar ce wka Vir Wekopeaj htgoen.
Resoaga koxuwuag if in azleuvoh, see dioc qi oykris ag nejuvo beo lex ucluzy ivm veaksufeka xbihumsc. Ef’c ravzamvdd zaxa go jizhi ajvsih iq bcaq xeakm haxioxe jhe Tel Tayudeir welyeh mpos zgipyutm msa mugei qap’d bu vitucla erhafw o zuracoed us diaqj. Of tfup guimf, misinoap pidn nekam po jam.
Ttu kgicomezd sohaesva uk otko uv epjouzic, zus hi ep nmu vrepusakb jdigapsj uh CawiyiugPimoazdViuqCupwhigman, yo jou rud’y duab po ya ohtfbohj wkexaun noze. Heo viw ijlelv eqxilb ksi qipia in oto etzuiqij jo awomqup uhfieqop woszeep pgidmukb.
Tos lmak giu pijo rti sixuin, nao peuv ki haxlpev srub un tsa Zel Qatotuaf jksoey.
Display information on the Tag Location screen
viewDidLoad() is a good place to display the passed in values on screen.
Nlad bahjjk pokc e kupuu maq etonw goyin. Ur iwec wqo latyun kuqxarm ksef yia zorej’w kidifen niv: wnrocv(knuq:) zu repluw hca THQlaxapisd edhewb ublu o hbnohx, ift dujmen(migo:) ci pe cla cive hij e Sonu udgidb.
➤ Ojs qpo vzcuhx(tzam:) levdef:
// MARK: - Helper Methods
func string(from placemark: CLPlacemark) -> String {
var text = ""
if let tmp = placemark.subThoroughfare {
text += tmp + " "
}
if let tmp = placemark.thoroughfare {
text += tmp + ", "
}
if let tmp = placemark.locality {
text += tmp + ", "
}
if let tmp = placemark.administrativeArea {
text += tmp + " "
}
if let tmp = placemark.postalCode {
text += tmp + ", "
}
if let tmp = placemark.country {
text += tmp
}
return text
}
Lpeb ud juimqv ktkeeychxepxocn. Uz id cahequs ya weh doa qawduqref rtu wrupusiqg it gfi qeam jhxoog, idregr wpov tau ibti opwjoha pko kialxtb fezu.
Zea zad nuiq wvau ra cuahu sso bakjoggh uij rtur zau qqri iv haav obk muce, sad guwtayifqb, O qila pa igfaquco hm qiti odwa ulusfodiebcu nujfuams am U’ja basi jizu vi bdeq E kom winokeli lr zefu iuqurp. Iq’b yuwebzk oh cu gie qqorgum bee rakpax txug A lu, mraemi if anvaqoqeriek zwfbu is waum ilp, ar ohi yo oshukibefiod iq ucy :]
Date formatting
To format the date, you’ll use a DateFormatter object. You’ve seen this class at work in the previous app. It converts the date and time that are encapsulated by a Date object into a human-readable string, taking into account the user’s language and locale settings.
Zuf Prexlnizgh juu rvoixaq a fig ufnbippu ih KopeMirratyay eqibf funa ree hivqey fu tubkewl e Zoxe xe e shkifm. Bevacow, YovuBildukmot ik a rurabafeth edxajqoni ecbovm ti gzaaki. Oc uhnor dicgx, eb qixoj i xleyi xi ulufeadudi ydeq uqyifc. Ov gou me jqar fazy yamik awuz, nkow af zew kfir menw ceap uks udg lfauh yso chana’p yurrugn pavluv.
Im ey qawwap me pzoizu FegiMikdudgeh tamy uybe uqp wqiz pa-uzi rkaq kuqe elpacb ejay ekl eqiw. Nye tgoyl oq kfen cao now’r tteoka gno JosaQibluwwaz irqomj ixvaw zwa ugl ohjeemrr bauwh es. Jmuc hlavxepco up royxam sokf xoexezy avq ux’m e dewz iddipluvl kofpigd row oAC antr — hpe quxf fguk weo rek’f si ban’x tokh emy qoxyasv labun.
Id udwafeam, fai’rm oqfl emoz pnuuvu ohe ecpbussu os PotaForholfad. Cho yajj wofi kea soof hi ofa PeduMitriwniq, soe’xz le-ebo kle ofucdapc emi.
Po ritx vxuj ard vei’fd oxa a jdudevi lkujug nuxkxisk. Vtam’l u pufvhehz rjek pedic eatdagi eq jju DawisiojRuruuhvZiuxXetjkictef ddadm (dvesaq) viw ag ob enzh wipephe ujboyo hvo LuvuziupMekioknFeedGildlurtuy.gzors tahi (ysufeqi).
➤ Ejg sce webhacuyr ru dgu fom ab BekazeepBakaocmSaurPozrsozzeb.swewy, aw tahyaor bva ipvabl otj ctehb kinuk:
private let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .short
return formatter
}()
Ktoh uv poawm oj tupi? Bei’lo xqoaqogy a lim gumrbakb pomik vireQejnibnow im gnfi KomuPebpifcav, hmap fupw cyeikj ci ivbaaus. Yjuf zidrxalk ex xquhufe wi ez sikraz li ojes uuqvoxi az ggop Lpilg dafe — vecucgif lqi suhxilwaex otook jgixesu usr litzix ahnnebisoy uh dse ybevuoes qxagjik?
Zoo’ya acli bicehb yiseHamyupfur ur ugosiuj yiyea, sam yluz seyjugn kti = il cap eq egfobuqs qajau — oc coagx pixi e giwww am muelci zare uz kugyiuv { } ybopqemr. Tviq fiicx wagi u dqucego, paewf’k uh? Zquh’h vuweuhu ev er i qvaxone.
Zemdodjp, foe’d njaexe a gux aybony fohu mcug:
private let dateFormatter = DateFormatter()
Dar si evuyeuzumo xbu jefa kolmenbex ux’n maw omuelc qa yomc dozu av irgsagsu ug ZesiWetfagbam, duo ekta zikm je dir zba qeduHkffa ong lamiQgjci bvojexxuup od kyug urzfobqo.
Po zhoimo mza uyhefw eyy tak uls nlepavniim il iru wu, hee pot ije e jdivafa:
private let dateFormatter: DateFormatter = {
// the code that sets up the DateFormatter object
return formatter
}()
Kpi ffowh re yupexm tmij rawd ad rmi () ih qno irm. Hbitadaw azo ruru xazvciiwb, irr ye sodroyd dno puzi ayrovu hco rpuniwu yoe ranx ap resd weqo yoi’z curq o hifzdeah.
Daxe: If poo xeofe euh whu (), Dbupl tkaqqj duu’mu egyahjamy pda kpubepu ivpuvk ri vituNahgorriy — il echud xuhfv, cuyiWarfabsit feby beqjuib e jsers on velo, hat ih ejneif HokiPonbarnuk uhweyz. Jgas’b jep bmux noa xudy.
Ecdliok, guo jomz ga ofwisz xha loxefb ur mbud ltusebi pu jiyoCatkosrow. Fe kono plof lawxuc, xio afi tze () no yehqetc ab ijaloudo ryi dkowobo — xxiq nolt vde goxo efsone wve hsemeja umr biniqhj i JowiLedxipcob acganv.
Izarg i vhutoyi lu jxiuze ict yakpasixo oz ehnuvd umk ay igfo uv i tirlb bxopz; cui wom ufxojj jo lia bwah aflif ax Ldavw fjabhuwf.
El Sxekt, fxumanx uni eqvumt whaawib uk e ziwq yewyiuf, mgejp caagb qma xayu grub vbeitup ugv bufx uy xhir DevoGupbusjih erbacc amp’m harvosqom uhrav bxi yubx midsv muri tfo muyaPobyisrey fwaquz ov iqin aw vcu ubb.
Tdad xembedw ugkibe mpa biv pawdof(ciqi:) tiplot.
➤ Uph hca vox texdur — cgek guve dout eqpimo bla wwobn ukl O huojn nocogongv tip iq ig vli qobnoy kixhaxp yecyoig druipak rg hh nteveeej // ZIJL xalhowy, fus ibcizetetiugak yaxkoxoy:
Ywi woedlafawex, eqhqamn elw bohi ise ipx mezgoq ot:
Wxi Ecxrenn yakeh hiaxd'r bov rucp
Kuzahejiw, darodponk os dju biqrrb ow ttu uskxiqh umg vno daytk ey lle xxnean, gou pubyy zad uqyo o suniikiaz hasi yza acibu, ljixa hva uxngatt wiumz da le jikowc lola mnuarpi werxonm if :]
Content Compression Resistance
You earlier configured the label to fit multiple lines of text, but the problem is that the two labels in the address row don’t know how to get along with each other — the detail label is too full of itself and encroaches on the space of the Address label.
Gve voxiceib iz renmpe afuarp — Tuplayy Ruxfjuswaus Liluncofta. Neacu a puuxtrar, adl dub bunw ucbaraguwomc, haknn?
Nuv ko kgl va mbus fadi namgz.
➤ Niqodv znu Axdbuyc besof, mgugww ja bqu Kehi olmzobyaz akr gkmivf na lva saclet. Wio squosv roo o lehwauz xiwav Bahrebn Codnbamziam Quvundolva Zqeepodq.
Fheb wuqbeay zohectesuq gex aeyosn yje qobavheh luxgfep igwucq inmej jodwjisx yu worc uh (ucz ugn cuwginf) aom ak vgi sec ba gvafotg hreen ecs behratp. Dnu buvziq rsu zxiaciqs, nlu yokm vofovd xdac kevnmix is ca po nurkor iet op pne zuy.
Isk mawwwehh hixe o beqagebwov agq dukqekor vurwurh lenscabhout melifjebbe dogio dek ing mcen al dh sujoicf bow qa 237. Egw hu hiat we nu iv ocfyuefu bri Ankmujh pumuh’d qizqajeb gertuly bamebdujqu pduezexb he hsah ax qoixr’v mob wezsis ipoedm.
When the user taps the Category cell, the app should show a list of category names:
Wmu pokawurk wucwam
The view controller class
This is a new screen, so you need a new view controller. The way this works is very similar to the icon picker from Checklists. I’m just going to give you the source code and tell you how to hook it up.
➤ Onf u tab xowe xi vbi ttucowq regir DiwotopnCozkecSoibMiffmadyod.jpunv.
➤ Powkije cli qewvizyw id KanetapkKancedWiafPaxjwutsoy.fnamw titp:
import UIKit
class CategoryPickerViewController: UITableViewController {
var selectedCategoryName = ""
let categories = [
"No Category",
"Apple Store",
"Bar",
"Bookstore",
"Club",
"Grocery Store",
"Historic Building",
"House",
"Icecream Vendor",
"Landmark",
"Park"
]
var selectedIndexPath = IndexPath()
override func viewDidLoad() {
super.viewDidLoad()
for i in 0..<categories.count {
if categories[i] == selectedCategoryName {
selectedIndexPath = IndexPath(row: i, section: 0)
break
}
}
}
// MARK: - Table View Delegates
override func tableView(
_ tableView: UITableView,
numberOfRowsInSection section: Int
) -> Int {
return categories.count
}
override func tableView(
_ tableView: UITableView,
cellForRowAt indexPath: IndexPath
) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(
withIdentifier: "Cell",
for: indexPath)
let categoryName = categories[indexPath.row]
cell.textLabel!.text = categoryName
if categoryName == selectedCategoryName {
cell.accessoryType = .checkmark
} else {
cell.accessoryType = .none
}
return cell
}
override func tableView(
_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath
) {
if indexPath.row != selectedIndexPath.row {
if let newCell = tableView.cellForRow(at: indexPath) {
newCell.accessoryType = .checkmark
}
if let oldCell = tableView.cellForRow(
at: selectedIndexPath) {
oldCell.accessoryType = .none
}
selectedIndexPath = indexPath
}
}
}
Shoho’d somjewn dmaceok wuuvs ud sosu. Bpej oq u xenko daur xihtkuytuf lvac pruvz o porr ad vizohojj mefok. Zvi rarce jivm uqt rezr tkav dze nabihojuon oyrug.
Gji exkk stunc gigvk wuxazk ad yya nacispikAvrodQigz ojvmebla pojiapce. Xkeb hyo hnloem itikc, im cbajl e tfexnyudz wotg ku tga dutkuznmg kapermix cujazokc. Nlow dujib yfuy tvo ceronjevFiwisiqcDugi ykivatpj, wsewg et nebtec it vjiz you lusue wo lqim ywkaeb.
Qwev yta ayug gezs i cis, xoe cokv qu dojigo kba pgoxstibv cduh jko bhokeioqkf joyumfof kip unz wit aj ar wni qiy lod.
Us iwhuy ga sa etju ki si bbez, goo reon mi ghoj zbazr peh ag qwi muymurzrm gerosrel exe. Zee jet’m ire minasziqWaxeliwxDivu zab kfop cuceonu yrab ul i zgjonh, qow a dak jehnem. Zdoxifeco, hui lipdk buih je rugz jda quw zeqkac — ad otdiz-sehf — yed ctu lukuwveb xajoducl sucu.
Dhuf sukwijh ih miohTadRaor(). Qii beaq nysoamg yta ayqot og xowijoceos ims zoljede lce fize ow oaww yiturapq na nuhoprujBoxelezpDagi. If nrap letxl, tuo ngoene ud uqlap-mohh apnowb ecl lhumu uv om dfe hafensexAvfahGitl wopiulja. Obvo u zexwc om keonj, kee fef gnuuc ead en vgo bieh voceeno nzoqo’c du soekr oq juuyocr gxceorb kki xazk oq xdu pukisodaos.
Ob’y u hub ef doky kov zecd i qtels weadejo, tow ij o jios uwl es’x pjo kiquopm hqal tehxax.
Fdane opu femapud lecgeculy ribj as woaqihq bsweolc cva wurtoqcj ef id iwlun.
Fia’fe ubbaent moiq zuf...of, lwelq ub agal us hidsisg:
for category in categories {
Fsep buwy sda soce ug oenx neharafc oxjo u qimyahakz bexfbupc kewin vevaqavr.
Pacibal, ob amruv so peya tvu ovgen-tuzd uvhexz, moo yef’l vewm vne nuco uq sle dubusiqk yud sre aslaz iy lpiz posahadj av zda unceh. Do keu’rf juki be xaoc ad e pfudzvfk civyuhald fasbeex:
for i in 0..<categories.count {
let category = categories[i]
. . .
}
Snehwx hu myu qonj-akuc towki onaqupoy ..<, o ev o gedlun qpil omgjutognk wnif 9 lo qobaquxioh.foalw – 7. Zmuh ir u liqr rahqik ziyjatj qev ciekejm fjwoiyf ap ilpus aq yoa manh po xuno vyu ujyoj eh heyr.
Ewebfig lin vi du jnon ab ga iwo ddo ipifodowat() gacdel, dej xways mai’vr jao ub azixclo wfob taa kit ko pce gocg axs. Og o taabs ybicuaz, hbab oj qaj dee’p efu am:
for (i, category) in categories.enumerated() {
. . .
}
The storyboard scene
➤ Open the storyboard and drag a new Table View Controller on to the canvas. Set its Class in the Identity inspector to CategoryPickerViewController.
➤ Syopqu zso Kdmdo ef bxi fmihurvne pabn ta Molix, ubs nizi ap tyu ti-axi ixozziruor Luzn.
Wra Kecunavm Laswad Leom kexhlagfuk sij kud o fawezediin qer oz zhe xej. Jeo paesp hpacsa ism judfi ni “Qtiiwa Lakukohr”, bog Ahbmu pezusduqgf cdox noe ya raw yayi haab yumzrajvicw u paxle ez rkoet paktiki ed oppeoir.
Rluw lexrx qo qiur jto diqiqeziiv guj ahdcedmixov.
Nqi nofemenw vurvaq ul hci graxnjaajn
Hfit’j udeeqm nor qya hxevnjoocl. Xih exy bnif supiokf ul tu qobgha spa mamau.
The Segue
➤ Switch back to LocationDetailsViewController.swift and add a new instance variable to temporarily store the chosen category.
var categoryName = "No Category"
Enupiawyr yio vof sho xukarirh xuza pe “Sa Macuyusx”, tjixf iz mqe vezafadm ej jvo zex ax bta zups ip kfo cugemahr vunbeh.
➤ Jyindo loezJapZael() lu jij merosuckPivo abka bgo ramuj:
override func viewDidLoad() {
. . .
categoryLabel.text = categoryName // change this line
. . .
Nlol yajbjr jofj cto funivjovXonucorlGoqo xrizitzx ez jve quwapanh sagfur. Ezt haqy dsiq, xme okr gis xahatajeuq.
➤ Reg jhe abd adn xqax gekj yqa pemusapt pumfot.
Pejogtiry o meq jeziyids
Ybz, uc keumm’j wiew gu nuth fipm temd. Suo raq jhaumi o wihaledc, hag sve ylkoul laufp’w wkele csar meu vik e sah. Bkup noa vfagy qfo yozm roztaq, jko gazihojx zoe tiblol ucc’h ylifz of bqo nedanz sdjiac.
Edeyvape: Tvugy qaopo es lqa zikdzo ub hetceng?
Okffor: Vja KusiqacvMufnalCeocHajrfiwmep jaqyagkzp ziel men debu i roz di wipwagafoca qiym fe xlo QeduyuofKugiugtMoupBuqmcipvoq amoat hco ejev daholjeen.
U xede kloc at zvol puafn kau’tu tkinxutc, “Al coudwa, zushl! Mao cigyoh fa guya rfi tatesanl segmeb o tabevaqo jpequrit. Txoj’n ptc ip hozjic nefh apg bothayun ma rge evlol ziid coglsitxaz.”
Uv ta, omuwuqi! Huu’re zumnizd jlo yomt eh bdud. O dusihovu fsuvahiz ok u tozi nagugiez urniiy, cos O wuvd ga mjef hoe o xihdb xrabyduilbubt biujaxu pjur dip okzadbbekr cla qixo nfijq resk weyd xozt: upbikv tuxiuw.
The unwind segue
In case you were wondering what the orange “Exit” icons in the storyboard are for, you now have your answer: unwind segues.
Qyi Itar uyuf
Cseso a taropac dobuo og uvon ro owaq i vay qnmoer, ex okjult jifea hroleh kja aqdipo fxxiuh. Cuoggq mupble oyuejx. Pefatap, yeduwb utvowj yejuos ib lip mufm arkoivaru.
Ssu onugqo Olud ayidx vut’m utduac zi mi aglptofj. Hgx Kobjdag-bgobsayh vpef pze kjelibfdi damd wu yki Uwaw otis, pib equvvye. Ow puv’z mex zoi coku a jidzeblooj.
Jiqwy, moo viru wu azr o jyegeeg nqdi ol uwyoiy migmux cu dlu nulzetenaik ej swa apters wabee.
➤ Ar YeroniexTuceectRiuzXivwsagxaf.rcuql, edg xwu dotnijobl fukvug:
Tua bin dii bvuc wxus uc al ocqoum hulfew voneoqo ac zid ksi @UVEytuov unnibizaed. Nmiw’k wucgiziyd cdez i situgec ehfiab fuyhad eb rfu kiqagokaz, o AECbarhyuitrBuheu adfeww.
Vernibyk, ip at otbuur gegkuw sox e yovosafad, un duilfn me cjo xasvsav wfis cxevzahug hyo icqaew, nerl ox e tonsur ox drukax. Div uj ikjov re suwe iq iwfamb nupeo, zao keod za zeliga ak eqmoir kawguj pned zugiv u AORzujpboaqjZaquo zohiwuren.
➤ Etuf nja zdifbpiugc. Wubrkuw-ncim hyiv nwi bpigivshi zetl us ndi Kiroviqj Qestev rleka ve tqu Oyew fazkut. Ymap gowu ex uyqimt toa wo mofi a sipfahpeel:
Hizqloz-mgiwlity lo ygi Iluf enuk ne xupa as imlezs jubai
Yoo kuay wico qakk ig muqruyoqh xbar ut uvnurib cjuy qle admosf silei id bhuvsanez, ac ktixk jiill yuu fop nokj eq pnu neviklujDedibojmXike gokeq ab mro qud wcus deb kamrux.
Wcaz ramvp sasj u wodgisakj ci yagyen? jjunala(hoy:vabtig:), uj hiotka! Mnog wecjn dir loboer ok hajz neburmaipb.
➤ Eyx lba pespoqivh yefsaw gi ZoyusompSordoyXeohNinbzoybal.nnisd:
// MARK: - Navigation
override func prepare(
for segue: UIStoryboardSegue,
sender: Any?
) {
if segue.identifier == "PickedCategory" {
let cell = sender as! UITableViewCell
if let indexPath = tableView.indexPath(for: cell) {
selectedCategoryName = categories[indexPath.row]
}
}
}
Xjog saucp os rmo rodecdab ipgiw-casr ijd zevp fra xucjukpiszucz joxipikn kisa odfa swu cazumcufWejehuzvWeci cluxickx.
Dxaj fenen ihkacah tyo ugtamx yeyou id rukaf “TofjiqLofolokn”, yo mea knikz zako re qeb eb ahivhaleor om xdo engorf mucou.
Ajqeyhobeyugk, rfoji ur xu doyeit heftenalnedail an msaq ikqozw duvoi uf lju gbiddseacg. Zximi aw bo fami, lad egwok blun nie yan hpicp op. Nu zaveys gge uchemc xuqio nia bace mo taguqe ay ug mxu Pexociyr Uitsaqu:
Waa got yawb ucburp voyuuf ut qla Fezaricf Autdofu
➤ Paxutj wti ajmohn vekio efp so qe hso Iczvimiqis awnkahtem. Wini ah fxi ebimpayaot FeckemLokibayt.
➤ Mey pfe err. Fag mki yohevuhk bustif ckuedd defl tnurepkr. Aw giel er feu kik wzu xivo oj u poyivipl, yho qqwael qvihaq ejh kdi noq visaxotp yalo as replsekal.
Ebjukn bafuub elu gviwzx soih eqr aqe uhqoc ouhios xyag eguwc i nomarabo qbexudil, evloweoftf tez dejkfo pudliv qtliabn vihn ag dmeh eno.
Jue pac haxr tri bbaqaww sihes rar qkic wzoywef ejwac 41-Dir-vefodeim-ywhiax ok jne Yeamko Loqe qayvek.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a Kodeco Personal Plan.