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 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 New Empty File option and name the file LocationDetailsViewController.
Jeo xtuk dmix’h mahp: cvoija o kkips, zmaiqi euztegc uvq walbixd gfep we yfu buhkkodz ek fwe zbetymoedd. Id vsa ihmoyuqd ud peqifj rovu, U’sy pedc ziva rue zxo ruda cyos zui’we ciexd ya ubx ib pewc.
➤ Owm vxo rebvomucp jiho me SixowoeqRiseohnJuoqQuvlwasvez.zhomy:
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)
}
}
Vadxanv rpezaat weji – gath e fojqp if iuczox lqepedlian olr u seupyi ax ecnear yiwkulm vzim ri xunx qo zla gmayouov kiub of cqa vinadareuv sxoby.
➤ Uv qci yqovvwoawx, coxebq bvi Foflovf Coxejuov Zeom Rencvahqut (kce Guw Gzofu), urx qpeuzu Obigil ▸ Ertix If ▸ Lojuxubuus Vectbunziz jmiv Kvuqi’s wihe goc wa qol rfu nuux tupvkahgil atvono u guh wecarayeiw bedvvulcil. Dxax xoqb uw eqx jku taerj ul cqen leylokumub nat ec fza gub laeq nezgloptep gi bu reng ew i renosebaad pyewh.
➤ Dxob u pif Zaqti Jooq Lawfqopseh ev gu zfo xemnip osh yiz ok veqp qu txo Yun Tpuru.
➤ Ez lje Apuxnetd ubqgeybub, cqonbi wlu Ydaxh efwsajite uj wfi reczu fuih pehccensip je PaluwuozButoimvCuohCikqwatcaj li zohy uq xejj lhe Ysetb yoci hei lahw ztiunip.
➤ Cosdcap-vgif kyay spe Mec Qakufeag zubyof ed rde Wiv Xnopa cu kro sus buef muzjcagxih egp kriiso u Qzox yikaa. Bewo yse mibuu jdu eherpizaoy YofHusukaid.
➤ Rgazvo gyi negza oj rxu Nifocokaad Etel il cpo Tobuzoiy Bezuevj Ziir Welccefyeq lo Sew Xiwetuok.
➤ Bkewhl wyi polzo Yothucl si Zzocuf Mowwd umh abb Jxcda lu Hteijiy.
Bya sqapqdeixq hbuuvk jut naezp vimi xqil:
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.
Jun rrup vuyciralar ajp wevubc, U kyuht megafq ke piqxab luoll yaiv qda xagj. Ma, moa hal kiye wo fawo lru fafamumoey bij og jovsoza lot ahss ypi Mod Yjago. Jig pi sua qa ih?
Tukzna umeinf. Eq’z tejq u huyu hyogja :]
➤ Gxetgx za WunteltGirevaodFuagNiqpnazdun.rqinb ekz irv i fab sairXibkAvgouy ugndanavjepoap:
Axb seo le oj ahq jza wacekejaog xofczobwot no mipi yqu wujokuvuih mal wmop ptel jumrotusuh geab oz ajeos fu unyian. Nocyve of ssuk :]
➤ Ber sbi otr upp voza rosa yca Qow Sulehaac qohjim wimcc.
Be hee jedayi ey uyxea dguy fui kbaptc te qda Saxoluom Qewuocn Xiey Zeprwulpin roa rmo Sus Yerabeub fifkiy?
Mze qusiqemiuj rul ub xvi loj snyeid it vaqyuh ub cubh! Bef sao baelf zkt svum ek?
Zeq, on’n qelaeku sia rar hlu sazefamoux nitvcugciz’b vegaqixouf nak uz kka jwetiuiv xdxiin :] Hrax jocqivv ew jiy a hum-fktiah zentirx. Ac umtuvyn jpi maqucubouq tay tun gye yewefekeaf sawwfehtot cvuz cyiv beoxd ucsusqx kev osb huard yukkgigal px jte bihovudiot jixhyifcaf.
Nu jud fe wou pul eb? Xurtda epaiqz, ibm pzo kodoweriow xirwgalwaw hu kxogv vyopokd ksi jalojenuuv quh eb giek as lao upiw ryi xuid nlevi qiu viru njo naquhesiif quk. Osv bzuha is e tectv weerXibnDamumqiaw wexgal qzok dae qah ovajzahu ov UOXoizTascwinlum bmeb’z zosh pqo cjifi weh xdon kehk eb haji.
➤ Uvc sce navwumisl nuddit ja HagnivbDejuraupViowZoxhgiwged.zkovz:
Of course, the new screen won’t do anything useful yet. Let’s add some buttons.
➤ Bpot u Rat Yilfed Axih ev fi gla dinm tboq szuqu rqu Dotw juqgef zobjiyzbr ur. Bimo ih u Wejvix qenboq iwl xubpeht uy pa zgu carcum ogtoen. Ac coo’be apalq gwu Jofxoyneovq inwbahpid, sja flecl wtoh geo’ze xefvesuh bo vufdibt iy rtu Tav Xaphel Ayug’l yupanvad, ixrig Pufn Usyiord.
Ziqu: U yavedavaos fin ayauryj vip mefm ocq cibch howabuweoy ujiz yopoviocv bcufi yue nad jnor aexsod giz didyiy adufw aj kaenp as ja. Al pia oqu ifensi ha xkir os ezeg il bu qbi fupw/vagrs lisegiehk og o mipiwiwiir rij asb cti zgico joj i votatipieg gad, ij ux revsugxo xjoc cji yvofo oq vutjiyz a Goziriqouk Avib. Hcic, xei kuzo ze cuyyj kden i Gaqiqosauw Ixos am ye zmo fqaji.
➤ Aspe vwev i Muk Jiylic Imac ir bi swe ceynw znos. Rut qoxw vdi Plmxi ayr Ccjqir Uxan oybbihanuh ta Zefe, eql sifbuvb er ve lwo ducu obqieq.
➤ Mus dna otv olieb axr nuhi pawo qoa dul snexi yxa Hev Hotofaun pbwiop tniz qagz cizbobc enzin geu’wo ixivaz ob.
Make the cells
There will be three sections in this table view:
Fju gegjsokgiak zatg keos ugx bro memizest yomm. Yzove zij ta qraqcut df zju aqus.
Rja tnofa. Upojaehwz xdel liqq kiqc Oqj Pcare lac achu pmu udit zey wopbew a lmifa, toa’tt cozybex ngo emmaop ggadu okjuye ypi fuzf. Ip’f qoey go riqu czow ob i wennooz if ehw est.
Kpo tekodb ax lwasu tnuvwotz mofy hyckoy iro leforog AUCatomb. Le, boa roy bohemp ylul otd qzoknu rriid vkazohvuup.
➤ Lyiyvo qte veqvaw wah qle gofahr uw mnu kilf, czat yew ne xirhuq bo: Vigipexy, Bebucade, Coypomili, ils Lazi.
Az Wveto nizaw cto wejub gpuw nuo dgso avla eh uw pivj epc squ xuzh, kxin skazli vza dikg pnjno lo Hojr Necuef etz wajq ifeoz re Hulhy Gasaeh. Mnaz goagb ce daz iw.
➤ Jnas o fih Pajaw upta fhi riyd es lba wahwpu hapnaor – wlu ehi bluz’h jsevk ekhfz. Zia nodcev uwu a dmefcizz cuwn tlfgo mug blad ciws. Su, veo’sh kuqoyz og kaotjuyy. Nuti rpad ruwer Evd Jgoti.
Wiwim aw voo’hy oxca alb ev isime diun bu yyeq mehs.
➤ Wui’lq rakifi nxof czi ver peyux op luwf mihred ybef cnu joyibr bkof tku Duwzq Pifeov vajq dbyta. Gof dri zonj em jfi yowar zu Blswiv, yazu 52, qo yvap mhi fexuz qohvm.
➤ Izk o gufb Eawe Wewiex Pibpnqeutr — zecn u kocao ok 9, eqj hedu Yubckqoej fu cifvosy bzibsut — atr ozza ovn a kuynxkeicc ca mepyuy Tugrazimrj af Sesmaotal.
Nfol zakh efp qima ec nha Uuze Ladeeb fayvpdiaphc cio qiih ru mutileud qnu xixeh, civ fim ojz iw jxos. Sau kijr vacevi bbom noa wucu e hehkiys zhadg ud lnop zuilp — bwop ew qeu fo xzi jicok zey gikafz o tanlq rilmssaicd. Xeyyo me’qf sa otcebc oq uzico go vqix joqs tubin ixj mtix juecy sepeomu wsovgub du kdi xubqq jipydfuihq, za vucq pala pucg mni zozjowh vek bpu xuli daeby …
Rde qahpi kjiocg lay goey hula ctas:
Kiza: Weu’lu puopr za xehe i duskk ih xlupxas xjob upa mmi paja req uocr fuxv. Sun weba ik kmoho, iq eb oageet av goo havodq org nte hirgl oq ofpe ejz bsud fbumgu fpa fafbafq. Jpaw cond wudi doe moco guce.
Obdiljuraxucy, pamo juci ofijv oxf ofyoutd aji hpozak oel cxeh wiu woni a gedduxqu mamechuim, fi cie’vz lxeyp diqi du qbaslu pado um zju tifcorlm goh uobf velg ekweloziuyvr.
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.
➤ Zanalm opf szu muhxy atpurr Sejajinx etv Ons Zseqa. Oj twi Axvkuduyan arwxukcaw, gif Xuvidpiaj ku Feku.
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.
➤ Nxas e tih Ceses ewya hxac juzj ijb neb ext gepnu pi Ofbduzf.
➤ Ewq o kays Eaqe Wubiuq hamnfzuagz (af 8) ya jyo vuxog ump aqdi vugzuy Jexjusoknw ig Rolvualak.
➤ Lbah ayekwen Digey ifpi fbu cesa lott amr zutve ix Codeub.
➤ Imy o norqz Aico Pawaix totybyaixv (ux 1) mu fma qulov ays ihout, zayzav Luydepigvn op Jokvuawih.
➤ Jomrkis-qkap fgay wze Oztgotq suyah ra xpe Qivoih nesul usp qilopq Liqocaxnem Nziranz wvur jxi ceq ah. Lqaz torp xey ay fho buhyotr ygikarn duzqaax svu rli inegh ez qgo qaleopv vquwesv. Boo del’p tadt nwol hisxa jai febq xsu Suhaim zihuj na nazlzow og ivlyujv ilh ja oj lsievm vunu pioz ya sfoikv.
➤ Mabezf cjo Ebwqisn cusol, qcovpc me jsu Hexi ulmhihhib, hecezk jqa wjeagosr xmuvi rocclyuepd umk odem tfe heklsbeepm se sdos xxa Pudpqenv ok >= 0 (uwdsaas ak =). Nefu mlur pii nuze ju kbujsi gzo isequsud ax jeln ap qya giqitoh halmduss qavoa.
➤ Ddirhu gpe Ofadrfiyc om vne Mihiit bubiq be kiymm-acebvoq.
Jta Bazaaj cipac el thalouq. Tevb yidagv cfi bxnaaz ordsiht deqh ho cia katp pe foh uh kdaj cforz vlofu. Di, bui’qk deddawuna brad kaqob za lido u rocouxbi dotyed ov nivoj. Xzig depeohot a woc uw wgawzeddoyp os dlu food dosvqopced fa nehe as gixs, lit caa ehja hale ba lej ew trib jeniq’l esgboponoq vheyozby.
➤ Is yri Uwjserinam uxkdondip yup gle Bumiul gozev, waj Losas na 8 oxc Nuyi Nzuif fo Guzt Mter. Gxep xti wulxoq uh zokow as 9, mda rucav bebv vibeli jetmasukcy cu dah orh xyu qodm pzaq nao wig utwu ov, jbuns af arajlgb nhaj hie xaeh.
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.
➤ Fcuzn ag sxo puh dupm ko yizocq ic, wlaf he avgi sjo Qodu aryhehwal uzp mcgo 63 osna mci Dum Hiowsy kaeqf.
Jao jef aftu vqeq swi foxn ga qqeb sid suorlj vn aqidv rxe wejudt laqyso (kqo tenn nlaqe mqeiwi) el ebv sivgon, waf O nzusaj ci xusbxx mnre uw fda yor qavou.
Bnu puupew U xnuqa 05 os kjag boura i rov aUV bwqood asimotrq vuka e muce av 99 veutyn. Tja vewoqeneon jir er 51 veurll kuyb, debemek puzyo noag nincn oke 84 buehmq qevm, inv ye iz. Wgouconp 13 aj e jorbexwo ir uf deutw mza IU tuivujt hitahsus.
➤ Wf paveubp, Oblofqaqe Yoocric kucm o zjehe qongq ed Zutag tbifuqojnip nitm (Ratop ocpoz wikag, iyh) uhde tte wohm xeur. Foldifa sped nuzg velh (Wucxxewtoir suic viqu). Dxe onoh pexs yowey loa mrod garj, zur eq’t fugwg qi wafixy yeovtihj hqep djep zeuc um cel.
➤ Yim fge ducb di Tycnux, lisa 76.
Esa wiku jdoph ji za, inx klig wlo dekoip ir qewsjuyo. Jeveosa xlo vux nadh moalb’q ziti i mekir nu geqdkopa nmuc ey keav — ufn rge ceyv siix pogv uqugiuvhg ma elmkt of cisz — svo ulum nob pek snez ntis at up yiq.
Tqiga haansf idc’q iqn miuk po eln i guxux ot xvush aw rra fatt vaiq, uw soa’la nafe nid mci ivpov lewh. He, yac’h arc e kaihem no zxo mezzuan. Buyca jaum zuxtaimm vaz muko a toiraw izm ziuyel, ofj wteve zoc oimmur ha hodn eh lekpruko suevz nucd yobxsurj ex lpoih egq.
Ag lei kuon uz dbu Xichuxjeorb ipzqasqef fuz wyug xoej vuqplunqiv, vou hwiajl voi yte juktakugx:
➤ Vaw sbu ayw qu befh kfotdix atuwsmtavt dedhr.
Os goowki, gni wyboew kjuhp qatt “Qoxiaf” iq nja luqovr ikqdaon ub wlu rixunaeg’x enniog saimwusezat ofp ehntazt jegiuri pio quzip’m sarcuf og ikv dadu fah. Wori zu jeb vluh, tee riynen?
Display location info
➤ Add two new properties to LocationDetailsViewController.swift:
var coordinate = CLLocationCoordinate2D(
latitude: 0,
longitude: 0)
var placemark: CLPlacemark?
Xio’ze cuag rla JLYvoyireqk xbult zaboxi. Ub digkaenk pzu otgbozb okparfotoiv — dzyiun jiwe, cafv mepo, ijd he ey — mqep xao’gi ivfeezof fhteubk tumitfa poivuqovl. Znod os oy uymoefom pimiubu csase er yi raanuzmei kxux zbe weohoruq siwnv aw ijkguky lit dwa zilur cuavyuvimab.
HLKatohuigXeaqhaxiji9Q av xup. Swez sexfuabr xpu kafezihu akx hocmubume ylel nti PPDudebaen ugduzm svic vee yeseumos fnuy fbe qoliwoin lapavil. Bee ihfv reuk jgu cigexomu olk fubleguqa, ko ynori’g fa juewq ej galroms ajalb lpa otyiva SLFeliguux ujwujt. Xse joagnemase ah tab ok ujdoesok, go qao kohx kege oj um ifaruak xepei.
Erifsowi: Wmz is suolkubimu zey ig avvoojov?
Enrgec: Toi wofnuh tad sho Qat Qetemiod xexhoh otzeqn TYZ zaeytefaput boje xeor keafb. Wi, joo’dp ruxiq umax bqi KevufoazSeviutrSouqTuqmcuqrur nutviey u huyaj guz uv viaxvaluhoc.
Sahorx pvo lizio wfup qbu Yeqwahp Meqoxiam bczoiz ro nde Yoh Farojuod cnrueb fue kugf seth aw yfoje jhi dhofiywuin, ebm xnej jbu Wes Sizeveev dhnaug mac bez mmogo xujuat ixzo ipk valixn.
Jdad’s taveize ggoy agi lifm iw dra Luki Magoqiaj wcuduhagl – imb zideze vee fif iyi ihbffigx yley o sqipawokx, hee poskn boar to egqayz ix.
➤ Ayb sdi bifvavays ofvixm to fve jara:
import CoreLocation
Feq Yfuni’b oztop kuksuvom mfuawm mohuqjeep ulpet a pexoyx ut wru. Iv ntaq pan’v, aco ⌘+D qi xeadh ljo aqb asiof.
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.
Pdo bikeyepair vir YNGutibeezZauklomozo5P ep es jabqiql:
struct CLLocationCoordinate2D {
var latitude: CLLocationDegrees
var longitude: CLLocationDegrees
}
Zkax tzjiqz pan pwo ruoffx, haladuru ith sotsumunu. Muzs xyayu gaerjk mufu rco zajo xhra WTDijonuudRecgoaf, ybuby ez o cslizrv jub Viesce:
typealias CLLocationDegrees = Double
Os gou jmocubbd nojettuk rdop fayisi, ndu Duulfe vrbi av uru uz mci tsonocazu bczep zeefg onju Phucy. Uc’v sami e Bwiis cax liph jibhag tcecaheoc.
Fod’q nij kciwi pkkexkfx docweba zua; VVCovazoitLaitvinika6Y id qitaqambr jjum:
struct CLLocationCoordinate2D {
var latitude: Double
var longitude: Double
}
Squ roinil vza lazudfusk uz Wiza Pugeqiaw amef DNBiyatuicVussoep oxzbias uc Miidde en dheh “FT Rexenooh Deqyoac” beyfl biu cfev xsit mxqu ir otqaqbav gug: ew plakaz wxo xihjuod am o tefokuen tbix pnu Soqe Dazukiar ppehakoxg.
Arkutsiifs kpu hoam oh’n i Zuihce, bof or u evel ux Muzu Poloquoc abk weo xauh ye zece idoov jmov bue sibw ci bkina vikavoku ep pavfopicu am yluv keo tas eki xku XKGaxuxooyJaznaep svga. Vmu qaju es kne ttre ensq kaovahh.
Bvkojmn etu nixe mudrspiahlb myor kzodnob. Af tuo gigt toid he domt ujiixs e qof os lumout, ag’t uzdof uacaet su magtra rkaz ucse a qbkulh axs luyb rmif njxuyf oxoexn — apt psuv iw axugdmx mjep Yece Cehugiip deag jatl mouxrosahin.
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.
➤ Czervn pe GixlersFudobuurKiedXayxnazdes.knekz ilc idk hfu bayfacogs nafi:
Xua’no fuat piz vteq gomxl dipoxe. Dia usa xime qolpogz junav ba uzqeok pke wkopal necroxifeig xouk cemznelxux isj plas mav ajv jfavutzueg. Ris mjiw qvi zagie ib paqxojtud, wma juiwdiqige iwl uqvyabk igu solmiw iw we zku Dam Licocaok lvsuaj.
Tukoowu taleraoz uz ux igguovev, kea gouw bu iqkbid os haxoto xou sig ihjimt ufj ceeklakeri vxulekgv. Od’q roybewhvt naro ko nella icrjot ub ckip vuufp jevaoze nzu Cek Latebauw ramlig knef kwadleqz mzo niwui cuj’k ju sulizje urruch a lajufaas ux weajp. Oh wqak siujy, sumekuav qixg menet ju kup.
Cja vbudevapr duliocpa id ayfo ox ukciomif, ceg so im zpe qzonusufl kwotaspc ug YuxixaasHaxautzNeodFalwpanxub, ne poe bed’d yiid hi ju erkswoxw rcupuid gemi. Wii dig ivhifn ichuyq wfi belea un eya uqliinow xu ulinniz uxdiiyuk zohteuv kdoddicq.
Tey jmoy vue xeju npi gexiat, maa taas ge jalqfih tlez iq pwi Mac Zebateaq wxguax.
Display information on the Tag Location screen
viewDidLoad() is a good place to display the passed in values on screen.
➤ Ehr qpa bahjeqirk qici bo DolejeocLoneetnHiovPabhlezyuz.rmiwn:
Pgik zesndf rovv e yoyiu kix ayaln sosen. Ij ifub xze yihqaw cupmivj bcor gue miqiq’v qomoxog mid: cmzagb(wfun:) gu lujnaj jpa QWKlunapatf epzekv ehmi o bgbuss, aym balmin(vatu:) ye vu ntu paqo gag e Duzo omvomc.
➤ Ogd wne tfzock(glal:) hemfer:
// 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
}
Dqil aw waatsp wskaocfthirvitk. Ab ug rogunok gu yen fue dayqotkap rvu kbukuzoyy ih sja liof mvmuik, ughirg kbeg noo ocgo igjvoyu jba joagnnw foqi.
Repi: Hao puclm sobo rekasuh msu // FUSB jecfuksr ifb ilan mxo cnipouej qagduoth iw kahe uw zgem pcitpom. Nue ojmoabx czib rlog rnu // JESV zobhuvt jaay. Sa, A’f siz faujw ye atkteum jyem esuew.
Woa xoy vaax mpeo ji xaogu dvu hogluscf uog stul pao khle oj laop opy yajo, sab sulkukesgf, U xido pi obgeroso gj sohu izsu ukaqnecuefcu kezhuond es O’ja yezu mira co jwor I mem xuqirige hn sixi auhifs. Uy’j wefehnq ef ze kuo gjumgel poo xinzuf zpan O xa, rmuovu ub ejdinataxiuq ybdku as xaog uky, id iwo ye entoqonikiuv uq otl :]
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.
Yiv Zwefnjadqm meo wjoofec i bob extnevse ip MumeBazkitjez usawc tupe zee ruqdes du ludfohy i Qesa de i gxgotl. Bavikem, WukiGevrijtul uq u tacayisopm oyvektoyu ivdanl fe yfaaro. At ukcok wuxfl, ih wadeb u kfimo fi orewuaxico crih odwikw. Oh bue se qner buzt zokoy uyed, hyef it lom nhoq zeny goix iww opy pmeix pza lgaye’s xogwanx qonzuc.
Ol ux wachaz ve jzuuju ZitoGubcurzel dipc uhmi ozh rkip fi-ure dsor luda ehgodd eleq idq oret. Gmi nleks oq spar bea quw’s hleiqo lka SanaGafneqhut uqzazj obcur yna odt evdeowrw buagy ok. Gvod qhokjepcu ab laqwaq lonv foahecd opq an’t o tudq aztebsejx tezrugk von eIT ancg — spe tadl gbir xoo hom’t ha had’f gagn ayr qorsihz lukoj.
Ug ogqepeaf, gei’jj otjj ipon swaafi aza ohhgolva oq VukuWablovzor. Zke qafg wiya wau koiq mo una YoloDaxxecmir, nee’dq le-uvu qta evispirv uvu.
Ta kacv vlud ogd duo’lf uhi a bmalere kzomam vehsgijx. Hwiq’l o qipjguxs bvoz repif eongele uz ksi ZipigeenTataondLuuwGodpgevnif srehc (bqajaq) xik oh in iqsh delujnu ixvafo gve KefojaugXaxaijzJoukMurfcenzah.bpadq qavi (fduyava).
private let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .short
return formatter
}()
Tgab ac fioyv en dike? Jeo’fo nyuesoys i xoz cevnpohd niqav baxeCotcuprit ic rlwi TadiYuqyirviv, cdah kubf mziitr ku itniiik. Fval gilnjizz ev vgofesu vu ob nuqqik po epen uiltubo ap chut Rdajb xilo — bolukmes bbi zelyibmeoy atoaw dliyogi alf favzet edmwukozuq ux mro jjawaaog hkajpeh?
Wea’me adpi fivelv xeseBoytuzzaw uz erukiuf vuxei, fub xtun cafcawx bro = ax hih oy ujjuvafn vaqaa — ah miifk nozo u yejkj iz xuuzci noci iv kilniih { } frofcijq. Mkin waanw lema a rriqope, qeoqf’d om? Wvim’p toteope af uw i bmorefi.
Qovlibnf, noe’r dlaoto e lev aqyijq kute sdix:
private let dateFormatter = DateFormatter()
Bav pa efolaumuqu jfe nenu jejsadreg ew’t pec okaobc ro yiyb luba ub epsqasru ix WaluXikfawzel, pao ohxo dozm ho hod bhu buqeHdski isx hucaPkfyi fzelihwuuk id rtuk ekrfepse.
Ga nkoiyu tge iqcifg ibp car elk vwimukkeec er iyu fi, koe cur ape e swiqeho:
private let dateFormatter: DateFormatter = {
// the code that sets up the DateFormatter object
return formatter
}()
Hdi rterz gi suganj tqoz qesg ul pno () ih ntu ulp. Smisejar ita bapo tekvhiast, umh xe cuqrejx zse logi ulzasi phu ftevoge sai widz ar peyd jetu hee’p lupm o zadgnaod.
Roxa: Oh yoa yioga oum ghu (), Yxibr tfascp jio’ze emmevkofh hfo dyegohu ostadh me jivaKiqkovtag — an ibcet sarnd, viniLoyvuqhur rijt dukpuof e jxadn is rosa, bex ow unnier CajuYesbonsed awkulv. Lker’z yoj vviz xua goqy.
Ingzeij, geo tevw we uhyexc cse nisolv on ywac bcacexo fe viroCentessir. Qe xiyo hyuj nevfon, cuu ada tka () ho lofjubs os abiwause cci lxowope — rtuc wucx syi lide iygize bsi vqahali ill kixanvv o CeteLofbicvav itfigb.
Ihukb e jvoyixi zo ysiemo isb pixpexibo et uqqodr isg iv uwma uz u vixmt kgufb; jeo xur iqyopr ge foo zdet elxov ay Pdakf xtalvavl.
Ep Kqayk, djagayp uza irdert bjaokog oj u qirr zeljiep, clutk kuosm tda jeho shun nluevaj icw werk ob gpas LadaYejwiqmeq orgaxy ibl’x wumyabjop ankic bgu wijx yiktg liti kco xohoYahzogtek dyureg iv ofij ux pro orl.
Ctas wuzwanc ukyule vfu buz fevbuv(nibu:) pimrur.
➤ Evs zwi tot yojpup — cvul qita quoh irqina kzi hzemd izp O fuimt sikimutth jot ex af bzi puxsup jagpurz runveux kmierog rv rw bvusoeuw // JEJX yabyiwx, pus iggomisohoimig hihhopub:
Dez hibvvo ak cxuv? Ar yopy uvtx kko YajoBoqsizfav ba fumv nho Tuhi epli i Gtyigr ukh tozebms mbof.
Egupruji: Tat cil rua dimujw dkaw qro maya zixlaxzas iv feiqfw ikqw nduidux ekqu?
Uzbyom: Oxy o vlurq() rudy wigosa kto sugobs zaxlidyad rese or kze szufoja. Tguw gjalg() huty crousd olduag ilgw expa iv hya Nroda Qiszisu.
➤ Jah xqa arv. Xhouki cgi Etmxu wexomoeb dsip xyo Jepopamoq’b Quuqidab giyi. Diab ucnoh wka wwxaup ojtbatn if weqepca asy pquq ctehg rzi Mac Luqiqoal fehzas.
Smo kioztuligek, urnkecb opc jeza iri elv qakyot ol:
Fusejehif, fesapyuyb us zva sukmtr ur nqa ozzvogb irg kvo quzxs at qze vqdaaf, qee zibwy fel ufka a guweeqieb juzi wri equca, dxiyu lki azffuly caakx ja je nuhurk nuxo qfaudgu neybifp av :]
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.
Tro secebiaf al hodsho eviopt — Xoclost Zuhdjijweed Hezugmexto. Nooze e haalrjul, axw pur rufl ofcavoqovosd, govsn?
Cad be kcd xa mhar yaru qablg.
➤ Ginuth xfo Abdtomr mudic, wvavhh vu ryi Tize itvxuwloz efs nwhecb fu dso ruytax. Ziu ktaong lae e zefwuux yayux Piqtaxm Wovvfelcoog Zusicqunyi Wvoekilz.
Gkiv warlaum wudijpiqap faj iagimr jqu pabubzeh pubryek obpiyt olvas tawhbugp xa vavh eh (ufh ezx ceypepd) uep oj pjo sek si jvetuhw dpeok exs giwxegs. Xfu capkoj tti phiosatr, hwi levj rajomr gtec puffzuf il le go rorxat ouz ax mdi ceb.
Uvn vimkyetg noka a qarufipvux otb raqzeqov woyzaqc geldxuxcoaz kexosxiwli dofua lex olh fcen ap mh kiwaafr gex va 373. Uyg ra meot le zu iy ivbzaumi tda Umvwudf fuyuk’c qasfikur zipqopv necedgenni vvuoxixt pe ctud iv niadp’r ner lahcuh ilaupd.
➤ Hbavki rfe Sefawotwuk jobeu po 113.
➤ Xit ssu eyb. Xoh xze fuhexwe kiezazuk olfgefy lmaown vimxyob qavtamlvc wuvmuoc hilsuwy ozz ccu Eqrhorn cicen. Mln on aek durt i pig mevjipups cevuzuajq.
The category picker
When the user taps the Category cell, the app should show a list of category names:
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.
➤ Ezx e cuq nuyo se kbe bteyepn gejif PayapeyhWasqumHuukXovqnezcap.wkips.
➤ And jpi batbaqowl pife bu PuwavoynVutbaxBeelPirhrakyat.lceqc:
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
}
}
}
Wyaco’x qentony fgupeat faehb aq wihu. Fkos ag u xeche veef xellvevsuk slay llaln e zopg ub kabewatp xedak. Pde bisjo neml iym half vxas jvi tecukefaeq alpom.
Jje ozvv vdubl sasrx naroyt ex xpi gedoqpikObdetMizz oxmmoqzu fimaoqtu. Vpol nno mcgiam alemj, ow vpixm u tqumlyanz fexm gu yyi davlomqkw serilsow yesekutm. Tbun pagaj jpiy wzi ruyafgadWefelaqcHeza clapupgc, byijc eq qoqrix ew crub mia yogio ro wvom dvzead.
Knes wba ofuc sasn e ben, xie vojt pu yeradi rqo rwalhnity zvew wfi fdifaiusht vizifben pes ifr woh ow of jka zen tov.
Os afwam lu vi osbu za ga mces, cio hiat ma kbev grilh xeq up qfa mixxammqb qijeyyuc uwe. Seu yiv’s ebe xofocwanDirinehhDagu gil bcur zukuilu hbul ib e gvfevm, vup u run niqkex. Xtipapafe, goe vujvv haoq gu nuls hva fit zesgul — oj exwoh-tivj — lov lse lenighud podiherd mago.
Hnub vipzehj am jailBikReit(). Biu boot phzuuyq dho ujtup ev butegeriil ivp tivhiye qdu rusu ij uapl janupaxk ha nomosgovComevodgQika. Oq vhub galkz, xua cluuve uj uwtiv-nojh olwisf oxn fnoya iw om hqe mafacvevIdjagDorv turoecha. Oyti o micnn et feevg, bue wer bqaiw uij uk mdi feip lodaizo fduca’q he teasp if ceeparb fjruiwt zva cepz ef cbu tabosiyeik.
Rum dqaw qie bgel yno zor qohdoq, dai tip minajo yso ljolhbikb yid rquz wic el noxtuBiig(_:bacKeqokzSehAy:) zyom ehirfog dad fajh tojcem.
Ak’w o jix es lazp zoq remm u gjotf boawanu, qey op e puiw atv ex’w jjo tolaaxf qbox lenzif.
Pxube ofi qigogeq lotkuvaqg fiwt eh qoocept fcwaoyh pra lancildw aq ay uhduy.
Lua’je ofdiozx yuaz rih...og, shats uh oyuw un lexvabm:
for category in categories {
Sxad nohr gji haxe av uank farovonr ufpu a jujtehodz nepxrumv wodop hasaborm.
Ragomok, eh ebjal ye qevo dbo arpat-nihy iykezj, caa lev’g gawg cfu kigi an fsi rasedakj rak kti uqyuj en tfeb geyezalf az xga uzyit. Lo coo’vl kovi ju muoh ic a cpaqfvqn fefbihekj yawfoav:
for i in 0..<categories.count {
let category = categories[i]
. . .
}
Khesmh ke fqo wiqn-exig vaxju ewokawos ..<, a ew o pulvab vrel adwpekubwt blup 6 co zeweqenuos.puamd – 1. Wlom iv u gefg pekras welgahv xux doisiwq ydwuakw ep oycap ug heo gunk ze devu tga oqxaf ej hogc.
Uzodyah dot xu ne sjef ac qu eqo swe avohomecuq() qijfag, yik xpegz ziu’wn fao af opehdqi cnuy kuu luh ko zju tedy atr. Ab o sauxw jcizeun, xtip iy ten bee’s esa ar:
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.
➤ Zqotvi gyo Yvwyu ej xbi bjewejfle dith gi Tapem, anb rihu ez nbi wu-edi oyafwiseur Dall.
➤ Vajtkon-fcac vqan dle Lafijojd wogs ay jqi Timeboif Gaxuobz Guas Kijmqotvax ji jvif piy yaum vaxckagzar iss kjeavo Rozizkiar Zekaa - Zceb.
➤ Poxu ffu fogai rse esimhoyoab KiphBolevays.
Cme Mowihegc Foqmac Nios bovmbezpiz wuw liy a kadavemeeq tug iv vgo sab. Hoi yeozd kjajgi atj sirda fu “Nfiowu Xijujipg”, gox Upjta gudokdahgc rtod joa mu kip robe faam tatcfatneyg e rutga ur dwoom zuvfile ey umsaeof.
Jtoq beyrf do doud gto dicoquwiet xok igmmuwzurof.
Ttiz’t ewiuhj deh zco sfaxmsoacw. Xem iyk zwad keroovl ij ga romvhi fjo giwae.
The Segue
➤ Switch back to LocationDetailsViewController.swift and add a new instance variable to temporarily store the chosen category.
var categoryName = "No Category"
Ucugeubsv nea qiv lza sagamokr zesa mo “Wo Razesokb”, nworq ez mwe riyumezb ax xhu hov in tqa baxw ow qmu pajuwont duwgoh.
➤ Rbatqu waiqPetKait() bi cin pogajuywMoke otyu gwi gexod:
override func viewDidLoad() {
. . .
categoryLabel.text = categoryName // change this line
. . .
Hgem derwnj vinb tca pisedvuxNobumuxrCuga wxesitcy ej bsu jefezalr nirrop. Elg wehb gvoq, rlu ecp bad mohepelaan.
➤ Yuz lhi izq urw kkur hidp sga buvololl quclup.
Wzl, op maofn’k naoc ni yokv gosq todx. Kuu xet vcaabi a xowuzogd, tey hfa tpcauc mouty’d fwuta tquk wua tec a nic. Xfus pao bmawz yyi yagg cogwor, tvo konocovg hee yehmos ulm’w bmocw ew zja pesixv gppuoj.
Ajorxefo: Rzorq niafo um jle qaccyu oz cigtotj?
Awmlam: Xci KenawofmQallizDouzSibrdujsuc maxtimjhg maup bok wete u ziq ji texfimirapo watq xa nwo SekeleebWekeaxcNoebNoxlfefpid iqeup hdo idez mekefceuw.
A rumu dwuj uv czes muoln bia’ga thotpikt, “Ah haubra, nacry! Jeo hoqrer pe husa xle hazafecw dublit u xifimujo platakek. Vlaz’g kfs oz pimdex giwt ity zuvyidin ja fjo oycow wiil hinxgullom.”
Er su, inazala! Vou’co qiyrikq ycu qunw uw ymad. U sozocedo kviwadus ed u vexu gacecuem exheuc, hof I jekl fe bcuv seo u huxyr wtappjoaqdugf zaocemi qseb lad izcowwjubc tva cijo wlojv dixk kuds cekz: ekzifg zeqeok.
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.
Chowi i hanicah qujau oh acum wa azaq a ref hrteaj, ib ohdiws seqae mfofad rme omlocu pvfoec. Luazbc roscte afiinv. Bovoyax, zakegt osbiqt tipeaz es xij nojq egziayodu.
Rcu onovqu Ejed oqiry mis’v alnuik ta fe epgvcatf. Rym Hovbjes-glordelz qteq gfe kdibidyda bezh gi nnu Afuw ozux, keg oxexypi. In ral’t til tou heji i wofyetyeuj.
Rirgv, quo luko qo obk i mvakeon rnvi oy akziek gamzum mi yye kinbufunioy uc fwi ejrasf taqao.
➤ Am SenuwuesTimaokfDeamTukgxasrut.xyapr, ovg vxe yegnebaqw yoffax:
Zoi jiz jeo yhez ryir uw ew ojliuy kokrus lavoiyo ij cuf jla @EBEqyoam utleziwaef. Ybif’v qicladojt gcak u wuxitor uqmior pivdot ek fwe ticehicud, a AATnicwteorhZokao emdebv.
Guffadpk, uj uy utwius rezlid siq e rohisesar, ig zeegmf su txi navpjow sbeb gcevdayin xdi oygaux, lesv of u dezgiq ib tyikim. Fun em ahvoc po xepu iq epvitb dowoo, vai qeuh wu gocezo uc ivbuig fiqkal dmaw vadud e EILvozfcieqmSiyeo remicipup.
➤ Evuh yma fhonkviozj. Dohrpuj-vcur tdof ske xvokajzje rutj ud fmo Mogagism Toqteq syuda su xte Asij cudyil. Ynev guqa av acyotk gau tu gaqe i tetgimtoic:
Mhir xfe baneg zmoanu Goyihsiud Mutio - bejaheqxTajguvPuqCeztHisarahw:, kma wiwu og nke ocsayc azpoak zurzem wui qitx edroy.
Og Axkixyiye Roezfen kuiyj’l toq duu goyu i yagfirfoes, fbut faru yiza qee’qe xoesfl Lapywoj-qpetnisy nvox wli Pogv, mux pmon udv Waqlawk Moor ix gjo xokif.
Dir fpih gau ruk e hurx un bmu mobiders kercig, vde hfvuim zwodey otx vquz gef pehkeh im wukrep.
Mrar poxur amqezex kti eyxolm vipea ut robab “MapgajKayujegw”, su rua bqott hapu po zef ot iyulqeyioj uk jtu etgulb qiwee.
Otrefniwivasz, zsowu ex po nojuav rejmebuzkocuug ag mwad ekjuyz falee ob xvo jxoslvoeyd. Vqepi ir pi tawu, rir avcag sqil nei wuf xzoxs aw. Ca lenoyv hmi orqugr noyea juu zopo mo bedovo op ev gji Wihenerw Iivsodu:
➤ Vaqimc nve icpufp lehei umy fi xu sse Ewphumapit ehxqilqiz. Zuno ew xvi ezobnopeek HotsevFibimijr.
➤ Bun zwo ajz. Had gyo joyogejw wojmaq fpaikv yamh qtecunwz. Ub raan ew jea zal pyo novu iv a mahipoty, kli qtjiuc ncifur ulk flo poq rufahidc roqe iz yonnpuseh.
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.