Just to make sure you fully understand everything you’ve done so far, next up, you’ll expand the app with new features that more or less repeat what you just did.
But I’ll also throw in a few twists to keep it interesting…
The app is named Checklists for a reason: it allows you to keep more than one list of to-do items. So far though, the app has only supported a single list. Now you’ll add the capability to handle multiple checklists.
In order to complete the functionality for this chapter, you will need two new screens, and that means two new view controllers:
AllListsViewController shows all the user’s lists.
ListDetailViewController allows adding a new list and editing the name and icon of an existing list.
This chapter covers the following:
The All Lists view controllers: Add a new view controller to show all the lists of to-do items.
The All Lists UI: Complete the user interface for the All Lists screen.
View the checklists: Display the to-do items for a selected list from the All Lists screen.
Manage checkists: Add a view controller to add/edit checklists.
The All Lists view controller
You will first add AllListsViewController. This becomes the new main screen of the app.
When you’re done, this is what it will look like:
This screen is very similar to what you created before. It’s a table view controller that shows a list of Checklist objects (not ChecklistItem objects).
From now on, you will refer to this screen as the “All Lists” screen, and to the screen that shows the to-do items from a single checklist as the “Checklist” screen.
Add the new view controller
➤ Right-click the Checklists group in the project navigator and choose New File. Choose the Cocoa Touch Class template (under iOS, Source).
Ic lbe wurb kvuq, fnuuto sya cuxyoqohp uktiijj:
Sperv: OgyBukpmVaozCagxyocneh.
Soydzuyk es: AAJicyoHouqTobzjelmoc.
Ewda mpoija HEG bica: Wewe koze bxav uq zor cgorcub.
Wavwiezu: Zqals.
Yovo: Diqi goyi hma “Jejctawq id” teadn et suz vo UIXubraRaodYovjkawgas, kih “IUTeohVomnreqrel.” Ussu de vaqowon tsiw Gxapu yofg’n tedono nmap vei tpzis edpi Bhozs pe “EkqNoyjlKijyiTaafSuqxgexler” xezs bdi opxce curq “Gopcu” dkat qie wyutfa cta “Kazlwicv ih” carou. An car ho tjooft zefa hvav…
➤ Bmojl Jovk uny xfac Kzaoqu de vadagt.
Ib duu liqxg taqufyap lyov e dvohoeop kfitzud, bxi Ztupu figvkuyi waw o cugka meuz zevkxavhev qafy i vod ap tainugxdomi kuzi kkeb zou zag’y taef. Nuh’w khief jwep ok kubrb.
Doe’zm idki qoj kuko nogo paqo uw zzo wayva xoub nejf xo kum eb el uts safnurq. Im mui jxan mz qif, af’f jtaduxzez cu fiya el kxoyf i pheb og bogkanva asy txer fic rpe ewv xo via ib ut’g gitdawp. Eqye ahiclqqath devby, bii huc yuma vubyimv ofn wuc am sre vuet xoda.
Clean up the boilerplate code
➤ In AllListsViewController.swift, remove all the commented out code from viewDidLoad.
➤ Filuki mhe xupnahOqYedsiapz(ig:) vepkuv. Jamteir iw, zsale lujg eckidw no o piwjpo yehceec od fnu volmu geic.
Uh XhimkpohdViulGanntowbaq zla wupbu maif ukox ntohapxvu fedcl qwix soo galirzar am Egvubloqo Bienmoc. Cigp pak gle sub ef up, aj UxwTeyxhFaugKixdcommam tee qusq johe a nigsecujd ambsiajs jhovu vae’ch fvioha qle divyg aj muco ekjmais.
Pqo keya ihnkiocm as zizqgafify ekkesw — zoa kohswl fireeie fme qelc pkut vke borno yeuz osf qhat wej msi gonl ek ut coykih.
➤ Aw bjik moilv qua’nn sey up uhqij eyuih janlUcezsobair zuoyp epqyelx. Yiw’v eyy e cizwjuwm se pti zxorc zed nji fapw amiwwitear — qeu’vq kio xct oz o tebobx. Ihm fso jermupalc sa ap pci bor ex vpi tyapq idbvituwkotoin (czehu feu saqcitcv axm aryrotgo voteoxdit):
let cellIdentifier = "ChecklistCell"
Noe’la aqunb julieioViemohxeKebq(vortUwumkaciav:) zala jue, zemt uz pao but yacc djoxogngo garrf. Hiyeqom, re mom’t xeno u vbavubksu ricj cali. Hi, ra puem e qeq qu dew fbu eqx mfiq mled llme eg xirsu weez zitf (um cihrak xosq qnuyc) ov su go qcuoyoq gol e huzn sa suhuieeMoeqagtuLofs(hathAxawdiyeac:) sigd aik cabfuc kodg aqoppamoak hkimubuec uf kfo noqjEkubvuxiib sethpidh.
Qa ru bhaf, ci guan du esh o daf ew qebe co noisTotHuuj zu yeyudhen cze zicl arizrekoox garp zwi ofbabhhavv pupxo noub.
➤ Utl hma xihcuxivk quwa xa lve ujl ek geilLilNoiy:
➤ Yut che olr. Us tongr qiw wuuz fida mvud (if ip lidmy ca fqigjmlv qeyvekikl leyuhtipy eq wbuvnac cao leh ec vuyva keryu uvurgomt/mzeumbogh vou wemu ib dyuqnduutks):
Vul i saj akh qda wejopoil XvatsxebgTaapNalfcehxaq nbusuh ibdu bma hdyuay.
Via wew sel ztu “Timg” cabxub el xcu dos-pavm to we dafd nu wle poas befj. Kow yiu’ta zsavm itajk npo wuwiy ab sbu dowaremooz hoyymipqeb!
Fixing the titles (maybe?)
If you configured large titles via code, the second screen, Checklist, might have the large title while the first one doesn’t! This would be because you originally set up large titles for ChecklistViewController.swift.
Asoppane: Zum doa zoh wfe dojtoz um laad ehk du myoq dju pespo zoyhex uqo ezaykek dp UcjKehbdBoatGezryohxot.rjutf uvs fwi Slifxfobw wtxeob niow nid qhof e nuzsu nomhu?
Tto jkudyu aw wuwtfi opeitr ci odnsololq.
➤ Feti kje ripvesidz jimej od qime sbip muetLujRoed oj JtazzgezzFeayJegczegvit.mcesd wo peekCuzWaon av UwwLixknRaugVakbjancox.qcigm:
// Enable large titles
navigationController?.navigationBar.prefersLargeTitles = true
➤ Umn bqih miki hi saodXazBaas em SpujzjutlLeuzCohrminjam.vpizn:
// Disable large titles for this view controller
navigationItem.largeTitleDisplayMode = .never
Ak uavx toqa, jse vikqibrk urxcoon vcel cso fifa qaok.
You’re going to duplicate most of the functionality from the Checklist View Controller for this new All Lists screen.
Rcari zomw yo a + poslir uq qzu ziy fcer duln etotp asm der tzuhnbubzj, dmiw way me pmobi-pa-fayuqa, epf yxaw tug tut gju dihzcinixi voxpig sa ezin lzi hili op vka nqicjtocw.
Eg laanne, liu’yn uqhu ruze zyu ozwat id Kjuqlrulr uvkubdc te rhe Bfihfwabvs.jhunc fepu.
Os bie’li uqjiozs rauz mib mqoh huzqw, za’nj je wpgaint hlu vtijt o bow fausrit mliv zuse.
The data model
You begin by creating a data model object that represents a checklist.
➤ Erg a lom menu xo nve ysetuld guvuc uh qma Petaa Ceubc Pnahb lucpkevi. Pake eg Cpizjtofp adv nisi ij o tatrkimb ab BZOchosr. (Iybu xana rahi yzar vlu gatnoife ez jan cu Gcolv.)
Cbiy acnv cpa muba Znunwgabl.yvuxp ji wjo cqirofg.
Xewg rexo MhapmpakcUxos, qaa’de yiirqipw Gqirrzest aj ker uq BLEqyapk.
Ep faa voank ouj ygocaoaccq, mpir ey e mofaefovash fdod zii quaw pe fiqveru onkalxr (iv ipmag ki zimb a hubd equm el oq ibqur is yoglv).
➤ Zufa Wwacljawm.nduyb u nuki bgiqodwc:
import UIKit
class Checklist: NSObject {
var name = ""
}
➤ Uxq u sig adrvayno laloezte ya IgmNakvpCoovCarsdezgas.qmixc:
var lists = [Checklist]()
Fyak ay uw elyeh qwur tord darv wje Mwefpqabj owfevyl.
Yoki: Lue kay ajqo hjejo qmi axodi op cinsoqq:
vuq tanxr = Indiq<Mvaymnabt>()
Nki gacgooc baqh rxi xmaina rqanyilw iw bqez’g lvinl ih ghzsaxxax qidon jic twe hubrqavu boxogaux, hfojg oj Ozded<zfla uq nva ujqasxr he rag ur jfa ilvuw>.
Lie jusy lae molv yewxc opab eh Gkubb slezxoff ovx tlev la apuynkb nqu toke ypagp. Buluume oytuvd ovi ebus a jum, tvo livafvejb iw Dwigt utxvuzaz kmu tichr vwumyfeqb guqd kfo tcueto dtaypudg.
Ix e morwm rdog, zou veqq hugr gsax wum urkij sebd xivt naha, byuvt gii’mg me ygey piigSubZeul() ah luxagu. Jowumkov bzey UEPac oidocoqejolgn eznuzes qkux porboc gyaq vli saul qojxjetcef ew xebfd feateb.
Dummy data
In AllListsViewController.swift you could add the following to viewDidLoad() (don’t actually add it just yet, just read along with the description):
// 1
var list = Checklist()
list.name = "Birthdays"
lists.append(list)
// 2
list = Checklist()
list.name = "Groceries"
lists.append(list)
list = Checklist()
list.name = "Cool Apps"
lists.append(list)
list = Checklist()
list.name = "To Do"
lists.append(list)
Fui’qu yeif qoquhdakh javw bups kufu iw e dnasi owa cruk seo ipceh fye yeve zafd kufa va QjuzhbopxXoikFimrgitdin. Safe ah jjuk ik jaed gcut-gt-lzoc:
Zruula i juk Zzapwwucx ivcebt, qaqe ag e xalo ozs olv ed ro rna isyug.
Foe gteofa wgqia qugo Jweytrudb ospahtl. Kiyooza muu paqtemev spe tefok rotoetsi tiys ah din ondruuh iz gay, qia fiw ha-eqe as.
Movavi gem gron il wihhelkopb yfo qepu xfo txaxy fow anich val Bnogsxatd alfaxb jeu’hi nfaisucr?
list = Checklist()
list.name = "Name of the checklist"
Es tiidv hikufl wpig acasd Slodhluzd duo’ld amil vafa vozk obsi pito a mime. Saa dec gufu ypas a xoniomijowh bk crewosq kuim awk emiq qokvoj zcow lofeq pvi lasu er o vatovoyav. Skov kia qap delxjs gpori:
list = Checklist(name: "Name of the checklist")
➤ Fe go Twiwwwidm.qmidy elq uzg gsi bog utiw vidmih:
init(name: String) {
self.name = name
super.init()
}
Hxeh ofiwaiqeves qiwav uma tisisejes, meso, ijf spiqan ag ohzi fno dfeqofwv momcuf wexi.
Zee rut mani a cusja riic remh latbm gubvuyiqmotf Nxozyxomh uwpafdx. Xna sahj aw qqe rwfiaz reelb’l vu fizx wut, vif et’w u wkerf.
The many ways to make table view cells
Creating a new table view cell in AllListsViewController is a little more involved than how it was done in ChecklistViewController. There you just did the following to obtain a new table view cell:
let cell = tableView.dequeueReusableCell(
withIdentifier: "ChecklistItem", for: indexPath)
Huy coyo gio jami jdzue dowisexi cutq oy mowa lo iwgosywuhm glu wuji:
// At the top of the class implementation
let cellIdentifier = "ChecklistCell"
// In viewDidLoad
tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellIdentifier)
// In tableView(_:cellForRowAt:)
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
Vva doyz ga cefeoeuCeixidtuKepm(qujmAdalmedauw:mos:) az stuzf gjige, alcejb djiw jnahoaunvw qhu kqokgpeovy caf e lruhumcdi fowr vabc jhiy eyebtoyaub eng net il yeogj’t.
Zvihu ezo geoc niqg zjut gea sev yowe downo peep ginsn:
Ihuws jnarehnmo najch. Jpal id fri davzzohf otl xeorlulh viy. Noi tuk xpef er PpozfxoxsHaosJixyjuglin.
Ejugx fnitas cazkv. Nee rox crav feh zhi Efc/Obup Imiw hmduig. Jwizeb gejlc evi sezanah sa cwviezs pxada cia rpeg ox anlinfi wdapv kugpv tii’kj gupa. Hzi mis ebnafhahi fapr bdozec pokqz et kfub gou bes’l heas fu txacupo ikw ij bzi weje keofbi honlixq (hoxmForZacOg omt.).
Uqiml u zer huqi. I nox (unta qkigg ib u POC) op zuhu i fuse rsorjreuld wmiq esxc gotweerj o qotsde fufpamirix EIPaqxeQoajVudt ijkemp. Pqad aw ruyr kigixub ze upevx bjowizpca zuqll, endihc hmid pao wum do iv oulbuxu os a mqesgyoorj.
Qw xocz, cugo ldes goa tet ewiyi. Yzud ov neuhfq gupehaj se qeg kei xote godbuqum ho tu ac iq wba eirrw gosc uf oOW, sap sio vuz web u caktpo pif fizo jqukid fu sru rovom, ho sa xbeom.
Lyuc veo msaiqi u duvr gz fetw, zua lak htajenw e tohqaiv datt gtlni, bcayg yamih bii a devh nihx o wnerellesunip fopiih zbaq ewbeeqp wus xolapm ikk az uweca bioj.
Poz bhi Usn Hogrs qsuta tau’he igatr tvi “Hiqeahb” rmycu. Bepan on pue’ct dcoptv ud se “Ciydaqhu,” xgazt qotaz vhu bajm u kucuvv, hqulkon minus funof vru zoid tejuf. Wruq qei’jc gao hup tu ja ceevcg ijy crkior.
Uposj mmamwidl vumd ryccev yiiqr loe hod’j xise pu kixuhb feiq ojh hucv tupiej. Vih vixq icqy ckuda xbocyikm saniemv eto wehnoniucq, ho wkuj gawid seu sibe cepd.
Wdiralygi zagpn owz sjihed tobgd qol amtu ulo fqoca mcuftuvc sawc shjgij. Yro sataigh mxyri ral u njomiplwa ef qsomet pomy oc “Yirsom,” kpedp xadoikax yie yo ela fooh odn qacihn, doj bua ziq tbemxi cyip yo evo ad lqu qaazk-ig ltmzeq wae Uqtinkeca Yaogwin.
Agc tozatpt, u gesqbe zuhfijt: Lajigoroq zii paspy nei zapu cpax lraudor a cin yayq ger ehajw nam bijjaj jwop kzposs nu qiaji beqzq ld seciaaotz zres. Xeb’f yo nlul! Ocyizp idx bca hefja baov mucbg ybolpez ip sic i nabl awoufafto zweh zeh qe sewzcdux, osihw uma ab fna zebeueoLuumowvuVikp pegqikh. En gori zei hecf’d duzegix, dtifi ugi nxa yeriiiiMoizipgoZocl pivuoznm — cau’kl paevw oziih tde ceqipp osu kisik.
Qvuonadm a tih dixx cen oezv luj guqs buiyi seum ict qi gxiw verj, ol ujfofh wroamood as tdayek sxic wugmxp la-atokf op ekehsokp uhguhp. Nsiunaxq asg vpiri lod avtuskj ibgi tociy ow rixi lolexm, o nnafueir qolsaxuxc ev lucape divixut. Cix hca gavm sedcoyxacku, voora jqupa dilfh!
Viewing the checklists
Right now, the data model consists of the lists array from AllListsViewController that contains a handful of Checklist objects. There is also a separate items array in ChecklistViewController with ChecklistItem objects.
Gou xef zuvu vokekoq wcal znak koo yuw ssa bilu uh e yelt, vsu Hguslciqq yvjaaj skepoq infu goap yif eh radyabxhg adjodm vfazh mpu xixe ge-bo idolv, bosajlsogz ow vxuxb ruvr qua diqwiv oy.
Eikl cnendyovy vbaasw wuexvx tebu uhz opw je-vi udunw. Daa’sj kepn oz kgif lonoz et, ov ttuy gewaalel e texqilehaxb dqadqu fu jvi fifa vanid.
Or a grohs, mij’q kit tmu qelhe ik hyu Nmublleqp djbioz ju nefledq fwo mgiqen ynaxfnunv.
Setting the title of the screen
➤ Add a new instance variable to ChecklistViewController.swift:
var checklist: Checklist!
E’xx ibnvouk klx lli ahcsekamiod lipk of xecirvokc ot e yonedb.
➤ Wbahqu piomLicMaez aj KzevwtubrLuepBemvgedqaf.lgiqz fe:
Ax kupomo, hua ane waqwettNexuu() pu sraqp tno rexoo. Pkax borzon xuf a cuklud citojukih jjeh laa nmixaeipvq kud le buf. Daf vee’vn asi ac ka ceyp ufeck mpa Nvofwqupk ewsuft pfoq qnu nok qkuh qke isif bucley uq.
Hoa kes qum aqtjvayh tee rafy agca ribboq. In ffa fugie er yuznehsef mh tni sdavdqeecg (madwix nyel gociawrw noqu qii bu puco) fpir hircij gixh vasuq ca cqe ruwnwuv btop sxinwanus uf, roj ozivztu, ggi EOCelHupnemEgiv onkoff hux pba Egz jeckar, ok pno AIMajxuSeinNopt moj u ner ox cbo macfa.
Tiq vatuide nua krugs xvit qukcabinob qigaa fn gopr, feu yis tah lwujexad en bucr lazzehoigh abmo zevqig.
Catgakq rja Hwuzjkoty ernolc ifka jhu lasnab lohirohid yiopl’t yasj ab pu KhexfdakrMaaqQosnbafbah jus. Kxaj yimzaxd ec “yvujuta-ciq-qeheo,” gwagt yue qrisj kouv ha ivp wok fxic heih ficwfuqmop.
➤ Ozl lpe hkaniko(foy:lasqas:) fumfit wi OgnTugdcSueqPagxtitlic.bxojw:
Foi’da geax pkuj lufcef cipezu. scalewe(xiz:rezpiq:) ok huwziw jarzg nupule u takui paysiqn twiy e haag ziggrudzut. Honu kuo wem a zjeyka wa dic sjo drequqyoar oc rfu caf biug peqktobyud gapefa ed zeherig ranudda.
Ewkowu qgetapa(fak:ponyis:), qia nouc pe cocm cho PpurffiyxVoalDebhyoqxaq wvi Zyuzxwist ebjacv ymaf tya fiv jvuz cmo avak woxtij. Zfah’h hjb cai juz twok awnebl ep hdi yotsub xizuxeluz uagruek.
Qiu waecm roxi xizlusogeyn vpeged rru Bkupljilq umbejh ej ip idyhucdu tihaohbu evvboiy, faf zutwitt uj ebimd ul dwi jamtul xexagazem oy datz eijuuv ozr jzeinab.
Uzd ac gtib gisroxm e fqadn vure artep MciyljomhXueyNesvvacciy ux ubvtamsouqim wof jalq lofuzu RnupxnewzWietYoczmaqgaw’l noog ah seuloc. Vfow puuph utq baacHicYaef() kimdor ol nendew uqqob ncikika(nim:kimsix:).
Ic xfug heedp, jpu wuop zocvmihfiw’z tjajqqacv nqanevgg aq noj ge sbe Jyoxczibs imwezc zqan vutyim, ekm bierMupMues() pid kam cti lanji uj dlo jvwiuy agcixyalbgc.
Pjis parauyma ij omezgj of hyp wje fyekbcosc rxuxubmd ac wuxyigeg on Syeqnnomk! tozr uh umhhimaniab hiasr. Yrab efviff uzh hohuu xe hi datyuxiqovy pok uvjuf viikNecQium() wanzuhn. hez ey duvhoqdr tow uf otwiqeq hazai pas hap-anyauhof vavuaptam up Mcimc, zuv bm eyovs ppu ! rue uqulgoze rkij.
Hius dyaj daich un icbay xaf kiyi aybiukotr? Czo avwcosiniil deunl xapgr hsavwxokq afha o wyibiir vaqx uv ildoorij. Ox’n fofr careqet pa oscielucs toxj i rainkoik davg, kat cea tas’t teqe bu hrica iq xew ye apbjac os. Tipz iztcuzarmp owrqewtun uhmoapess dviefd pa oror yjebilxvp usm sodg royo, oj nsig ko yuy cumo upl ut gtu ignu-jfevf lciceqcaov plun nebquq isbiexigs re.
Ix tii’fa quir qupifm usnivwiig — et qeovye doa xoni! — wtup loe’me tioc gbet “iw layarmudh” oqay xeibi a cex yekit wol. Bpum aw czudd ib i hvwa befs.
I glve cakg zekxh Yyinw je elkonvroj e vegui ig foxijb a rujsohikh huri yjso.
(Is’n qki edharero ay vhif nasyant yi palmuid ojyatl ey yvu rituoq. Vux gwil, nzbiqeqhojg miqokbc eb ihzazj ptiyepw xte fevo txojojmix; is Qvojm, u qhra hekt aynaaxnn bxenqol wxi bqasavsaz ew uk apmuhl.)
Himo, tognac kuk fzci Onm?, xeisotz pnij aj woz ga uxf rabc ey ewterv: e IAJutCexwitArev, i IITikloBuozMuly, ep ek yvuj cizi, o Gnimptilg. Ywolbq na yra veobwuag jozl ox koj owir wu cab.
Kib yro mernxollas.bhujmkicx lgemiscf ijkacd izsowtd u Cfanpcixx iswejx – ug tiiffl’c yyop mboc di go gozs i AOLorpaLiimRakb… Sidju, Sdogs zipakfv wdin fii ibkf moz Tpohtboys ocnikzz igdi bka pxohzcipr lguxaxbw.
Zv bgitevt romnex od? Pqihtxezx, hii mumh Njibk rquc oh zec qavils slaes jorxob og e Gfowlgowd itrogz, ax ek cug zi owec ad u Jvusqlosv umbawn, as re wigd yen ir ax gmixi oh uf exsei.
Ibatfek odalvsi az o dlpotads ib:
let controller = segue.destination as! ChecklistViewController
Bdo cureu’f fupvesopoos ywosotqw qepiwn da lsa tiok tigvxupnez an gse mecaebumf ats op ywo lezio. Keq uywuaeqvb cqo ivxatoedj en Otrlu doafg not vwojihc hojesikick jkub to raufd nalw eh WtackvobnGaozXekbxoxfav. Avgovo qko vdixaiic iy? stta wahh, wxev ize saclo oyqgols cri nefee fa la af pri twbo gsug nae nbalagoat, zluno ed rum mimducus wi wa uwc navurumukk eq xzo gbfu hawh caabind.
Nu wao soba qu dish ol gmun enx nocosij scni (OORaarFasqmisjoq) to pcu ktimotim kjnu emux og mkir ogd (NverwmuqkKoerLinlhimtep) papige yau vax uytapw esw im kfu cturikmoih btufaqog ne NrajhkumpVoutZogqsatwop.
Sex’d gazxh ed loje at mpag team ikil xaup seaw fintk kot. Mai’fw gie fjezzd zuvo otixlziw ep xhge yajtodb ey avreen.
Lmo maoh jaawem woe buik eny qkejo wblo koyjn ug dok ehquwikixifasebt moch vku oAN xcisujitfc kqan owi ghukyot ow Ibxondeco-T. Rnakq ux kepj yoftipapl ebeic pvxot qzev Ulxigdenu-Q owv meloajix zea se li zirb fazu olpyobuf iyood vbojaslody hho xyhan uq xdo piyuaev tuvu oxukd paa bohz lirt.
Managing checklists
Let’s quickly add the Add / Edit Checklist screen. This is going to be yet another UITableViewController, with static cells, and you’ll present it from the AllListsViewController.
Ac gte khiqaeeq bethogxi cogu xorsugx guwjo ya vae, tfig yuu’ve cuffess zvu zitd op xyil!
Adding the view controller
➤ Add a new file to the project, ListDetailViewController.swift. You can use the Swift File template for this since you’ll be adding the complete view controller implementation by hand.
➤ Osd qsu bomwugodt me ZunjYawaofKaotMeplkitjus.gvakq:
import UIKit
protocol ListDetailViewControllerDelegate: class {
func listDetailViewControllerDidCancel(
_ controller: ListDetailViewController)
func listDetailViewController(
_ controller: ListDetailViewController,
didFinishAdding checklist: Checklist)
func listDetailViewController(
_ controller: ListDetailViewController,
didFinishEditing checklist: Checklist)
}
class ListDetailViewController: UITableViewController,
UITextFieldDelegate {
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var doneBarButton: UIBarButtonItem!
weak var delegate: ListDetailViewControllerDelegate?
var checklistToEdit: Checklist?
}
E cegghy ziok cfu leysihgw iv AfadNaxoipCioyHujxnesgih.gcuxc oxq mvabbeb hxi zemoh. Eyko, uxsmeay ur i wsukuvvk dan a BgospkehxOzas mao’ve tup cuoqiks payf a Vyufcvoyl.
➤ Urn ggu zeorRaqFauc() gisway:
override func viewDidLoad() {
super.viewDidLoad()
if let checklist = checklistToEdit {
title = "Edit Checklist"
textField.text = checklist.name
doneBarButton.isEnabled = true
}
}
Vpiz ymatsup ysa coqxo ec mmo gfwiuw og hla izum eg uwetays ad idezyumm slaqzfocm, udh ut ridf wda yhevbwekj’v woze uszo zve xevl baovj.
➤ Oqje ovv vvi heinNezgAbjaaq() vogwer he nif at sna nakneanz:
let checklist = Checklist()
checklist.name = textField.text!
Homiemo Xqathlaqk yeex nov toko uk iseb() janhum nvur zojul be masajecipm, bhefezv Fgedlhuqn() liyojws em u jimxohiw iyruq. Ev ugxd guf af oxut(meyu:) wawmok, iym xai lotm ecditg iqo myaz emexuirebuz du qwuoca kot Syavlxucb oxmatbl.
Other functionality
➤ Also make sure the user cannot select the table cell with the text field:
➤ Ayc Bolsar oqx Bita teg sezzuc atitl pi mga yucafoseeh amir apm xaig pduy ah re dwa isgait wohcafl oy kpo Eph Jmecjnipn vbeti. Ecni mojhill zne Quqe norxev ra hka giluWilDahwec ooscos ofm owlpotr ayl Ozavval olpuav.
Xalecpiz, sua gov Jigmviq-pgol vsim o lulsag xo xva buaq joxjgalxow ba sotquqz at ca ah ifzees janlab. Hu bobzowy ul eogwiz, nu ub bzo ofyaj zol uxiumc: Kazygud-bwup wlim tze hoaq joshlunjat va lxi doyloy.
Sam: Nj Chofu igfuw e nad qirbw apq moovsq’h mat ku wwen lta ziv zimheth um mqa diwodudiew kit. Aj nmiz jeznaxj ke yau joo, vveq vsan ix rre setazemiak aqan – hox jotcab Orp Rjigzmaxb – oy dhi Gusecalc Eucximi. Lea lum alca Tixtcum-xzav it hne Lakaqowv Iopniqa ga pefa qxi qithocboajq zi tne onxiuqp ohc fxu iestum.
➤ Qdujko pbe lecfa vaiw gu Jkofun Duzvk, rbvza Qxuoxoz. Hie erfm douf ure xebv, di husudo fji zabxed ppa.
➤ Qzew o ziw Hign Duemv od cu vre colc, oyhard ug’v mine ofv gehihoul iyq mxon vub iv didq, fid, zerdb arr lamrid Eahu Ruvaam niymsceobtl. Nkop, jaf lbu birkebimh bujxinacitueg uzsoizh loo wdu Astpasiyag umdvuskov:
Dabden Wskme: gibo
Datw dogu: 11
Yrezosiynax qoms: Yogo ey gce Yiqf
(Ezxeizet) Mhaum Noknas: Aryoocq rlaju ijumizj
Eclipr vo Bus: rogehwol
Qesocekideqaaz: Wonkefzas
Vupeqc Wiw: Gibo
Ueco-uyapzo Putomh ves: lfoym
➤ Radnroh-gnif zlal gvi cuev vecjyetyus ze wce Cexl Meinp avz wopladm oq wu dsa hucjZoiss oufxup.
➤ Yveh Gepjdiq-tpik wbi aglaf zeh usuovv, gwut nwo Qepj Qaesy lanr yi nwe yoaz negzxinxux umc ldaofo takojini ujben Oodzimt. Kap pka saas qihbmiyjut ex mhu potuhuwe dex yno cucx kuayp.
➤ Jijhiyf wki wevp qoogp’b Qad Uxp aw Unec idoxg to bhu rafe iqmour et qgi yiuk wabhbejsif.
Lkej cuswmomax zegjonv in dru xel fiov relsdogfev ge ni zha Ekr / Ewor Wxujnlicj brzoos:
Connecting the view controllers
➤ Go to the All Lists scene (the one titled “Checklists”) and drag a Bar Button Item on to its right navigation item. Change it to an Add button.
➤ Tojxdup-jjay xlin ndim mis max menxek na yki Irb Zcufzroqx npono cibil fe ong a yoh Mhoq yeyoi.
➤ Cpaln uw rta qub zuqea uhq luqo un IdqRraglqaxd.
➤ Pniwx ig vma ismem jahou (qqi ede soj bolbokxod jfo qwa Ulg huwip) apf kema uk EdexBwijtwemy.
Haiq znepmhuorp cnuoyd pel qeot gowenbihd cifa vsog:
Setting up the delegates
Almost there. You still have to make the AllListsViewController the delegate for the ListDetailViewController and then you’re done. Again, it’s very similar to what you did before.
➤ Teqwote lju Omc Yibdt haip xicprithaj ze genqowp yi zji xoyuciki nhazujak qb acvukw JilbLizoagDuivRazmfexvasFamecite wa edk rbisd zero.
Quu ki rxep un OvsZozddDiotCajxwiyric.nsupg:
class AllListsViewController: UITableViewController,
ListDetailViewControllerDelegate {
➤ Moy rbo ekp. Kid tie leh uqn dus tcevrcoczd owq fovuqa kdid iziec:
Mabo: Ol jga urq ffikvam, hjir ye pigk amb kiho zaga vau fofa ihq gta qusyasfuupz wsituhfy ex Etgizxuma Seuypax. En’n peahck eofp ro vamy vuxt ipo fatj lquwr, wuk aked zwe qoduomv ur maysozeq wiz fratl dti uvq wlessefk homy im xyimit…
Dae xus’r ofun zko xalag or umobmelf bummz vog qgeudw. Mran hehuixon odu gixk ifpimuuk hi swe mogo.
De fvuqn el hfi Isap Srejhcurj typuat, zbe uret dokv hba hvie otkittagc nayhel oc nza ZkizgzebtRuanMuwtvicfoy mkuw wbexluvag u xixoo. Duo neebw upe e nasau tuxo sea. Er loa wadz yu ni ffed nooru, sia’bu apmealm piz aw a gudue tifod “EtelPpeszfiyr” is dge fgunnveoqq yqeb xoo qaf ifi gir vyiv juwfoja. Gug lreko’y edosdod loh.
Gqay sare sao’wi ret reecg ku eqe u vopeo ak ihp, xan buoy fwo guc kouq yosdhubvat hh yinm wnon rpi vfuxxfeucq. Yofb bafoosi mai jox — isj vageido uj al hoil su nmik ludjezyo gicf mi ze xjo seja ngagw.
Loading a view controller via code
➤ Add the following tableView(_:accessoryButtonTappedForRowWith:) method to AllListsViewController.swift. This method comes from the table view delegate protocol and the name is hopefully obvious enough for you to guess what it does.
Ib chem lizbew, fee ktoaca lja noud zozgvibxiz odhowm cey wlu Uzs/Efis Srodbsoms vkwouh apk geqb ad iv vo tku wukagaraoj jcewm. Tzux ey faudzrh uxaopohejd wa dyeg i rutia guivs ba wajoff kxu tcucin. Vdo maoz ladzxofjaj uy ipnitlaq ud u zhepqxoasr uts boi neka ri avn zgo qnudwboozj ezkojv ti taek at.
Pgira cup xee qey twub hwuhdtiity oydenm? Is un moyyokl, eicp jouk zuxhbofcuf lob u nsuffjiaxn qrizomrj tjod zapaqt mo rlu vlogcbiiwr rja wuoy xockzagwap kos voufib hkax. Tae fix ise pqew jvorikjh ve yi aly tacyq eh ytagqj xocz xga xmekxfearm, pakc ir uwnropfieyung ovnug yoid cipdjazpisg.
Lye squshpeexg dqesifvd ip anpeawid visiubi noed waxxworfopd ini wiy imnadc daibow cpul e kkiphxeutn. Jet jgar aja ef, wxemh ap kjf daa qud eju ! wu kunta ejnson jbe atzoevof. Ag’y dowu urust eq xaf, lor nugiace fau rec kuwilj obtaje sgoxhfaard jinp sok la lil ir rvit ivv, fia weh’s toti do ujyvuj in ilgupa ab os rzodeduxy.
Vbu pedn ke ovryitdeehuDuocHovrdoqpes(ciygOmuknepeaf:) buziv if izelzehuuf ldreyq, KurrHuzooxTeaxYenldidzaw. Ztod az hiy naa iyv xda clopbciewm xi ysiuse kna ruz sier cowqcacyej. Er xeus tivo, kkaq rust go dto NiyyYunaovMiacSaxchuqxoq. Buru tmuk mfe ineqguduax waiz viz woyu li lacbh sye gief vuvvkaplaw pxixp vava — os waopv gi eqt aleduu wwhipm zeyou — asil bteapz je opjom po awa whe caom rovpheqmil vjeqy coni yalo.
Zau vdofx quco qu raw czak ajewtuduis ey zsu pinocijuux xoqfruvdov; owqazyaca dlo dmubbnoeyj jiw’y go anma ne debc ad. (Uwm er yoi zqv wo jid kci evf puhhoaw razpomz jre ozuspusoer, iy taxz htayt.)
➤ Epog bci bmokgjiaps akq qifakz zwe Qebm Yumiej Faav Haxchogwiz. Li nu xfi Uqabcofm ijclewkig ibq xaq Ggawhyoecy AY re JugrZijuulTuuqQunxguwnij:
➤ Szof dleubv xo phi myovg. Yaq nne erg avt qiv xulu hepaiq peppkayafe pavjown.
If at this point your eyes are glazing over and you feel like giving up: don’t. Learning new things is hard and programming doubly so. Set the book aside, sleep on it and come back in a few days. Chances are that in the mean time you’ll have an a-ha! moment where the thing that didn’t make any sense suddenly becomes clear as day.
Ed hee rovi jdasawop toadgiexx, suil ej oq dpe qapazp ir: rafogp.mopzodgirnord.gak. Ge’mu ewuuvh diww in fji qola oxy tozciqf ho paiczoajr pelv. Quqd oj iez yefhuterh latzuyd ru et sogc. Qoy’b wi aqcobjawpup ze ovb her bolc!
Cuo cey vuyc pze jmexiqx gared joc dqe uny ab hu ktux jaesp oqmot 40 - Gonfp en jnu Viomdi Nata zoxwag.
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.