self.tableView reloadData]; } }

You ignore a tap on the cancel button whereas you save the new tag if “OK” is tapped. In such a case, instead of implementing the change protocols to the table, you fetch the result again and reload the table view for the sake of simplicity.

Next replace the placeholders for numberOfSectionsInTableView and tableView:numberOfRowsInSection with the following:

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section]; return [sectionInfo numberOfObjects]; }

This is pretty straightforward – there is only one section, and the number of rows is calculated according to the results controller.

Next, modify tableView:cellForRowAtIndexPath: as follows:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"TagCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } cell.accessoryType = UITableViewCellAccessoryNone; Tag *tag = (Tag *)[self.fetchedResultsController objectAtIndexPath:indexPath]; if ([pickedTags containsObject:tag]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } cell.textLabel.text = tag.name; return cell; }

This shows a checkmark if a tag belongs to the pickedTags set.

Finally, replace tableView:didSelectRowAtIndexPath with the following:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Tag *tag = (Tag *)[self.fetchedResultsController objectAtIndexPath:indexPath]; UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:indexPath]; [cell setSelected:NO animated:YES]; if ([pickedTags containsObject:tag]) { [pickedTags removeObject:tag]; cell
self.tableView reloadData ]; } } 

 You ignore a tap on the cancel button whereas you spare the newfangled tag if “ OK ” is tapped. In such a lawsuit, instead of implementing the variety protocols to the table, you fetch the consequence again and reload the table scene for the sake of simplicity. 

 Next replace the placeholder for numberOfSectionsInTableView and tableView: numberOfRowsInSection with the pursuit: 

 -(NSInteger)numberOfSectionsInTableView:(UITableView *) tableView { return 1; } -(NSInteger)tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section { i d < NSFetchedResultsSectionInfo > sectionInfo = [ [ self.fetchedResultsController sections ] objectAtIndex: incision ]; return [ sectionInfo numberOfObjects ]; } 

 This is pretty square – there is only one section, and the issue of rows is calculated according to the results accountant. 

 Next, modify tableView: cellForRowAtIndexPath: as follows: 

 -(UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath { static NSString * CellIdentifier = @"TagCell "; UITableViewCell * cell = [ tableView dequeueReusableCellWithIdentifier: CellIdentifier ]; if (cell = = nil) { cellular telephone = [ [ UITableViewCell alloc ] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier ]; } cell.accessoryType = UITableViewCellAccessoryNone; Tag * tag = (Tag *) [ self.fetchedResultsController objectAtIndexPath: indexPath ]; if ([ pickedTags containsObject: tag ]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } cell.textLabel.text = tag.name; return cell; } 

 This shows a checkmark if a tag belong to the pickedTags stage set. 

 Finally, replace tableView: didSelectRowAtIndexPath with the following: 

 -(void)tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath { Tag * tag = (Tag *) [ self.fetchedResultsController objectAtIndexPath: indexPath ]; UITableViewCell * cell = [ self.tableView cellForRowAtIndexPath: indexPath ]; [ cell setSelected: NO animated: YES ]; if ([ pickedTags containsObject: rag ]) { [ pickedTags removeObject: tag ]; cellular telephone
selv.tableView reloadData]; } }

Yuu ignore a tap on the cancem button whereas you save the new taj if “OK” iw tapped. In such a casd, instead of implwmenuing the change pcktocols to ths tabnx, you fetch the result agdin and reload tfe table view for the sake of simplicyty.

Next rfplace the plasehokqers for numberOfSectionsInTableView ahd tabltView:numberOfRowsImSection with the followinh:

-(NSIjteger)numberOfSectlonsInTableCiew:(TUTableView *)txbleView { gzturn 1; } -(NSIhteger)tableView:(UITableView *)tabldView numberOfRiwwInDgction:(NSIntejer)secnion { id <NSFebbhedResgltsSecyionInfo> sectipnIifo = [[self.fetchedResultsCoitroller sections] obtectAtIndax:aection]; return [sextuonInxo ngmbefIfOcjedtx]; }

Fhis id pcetty straifhtforward – there is only one xesnoon, and the humber os rows is calculated according to the rtsulta controller.

Next, modify tableView:cellForRowAjIndexPath: as follows:

-(UITableViewCell *)tableView:(UITableView *)tdbleVmed ctloForRuqAhIndexPath:(NSIndexPath *)indexPath { static NSStryhg *CvllIdentifier = @"TanCell"; UITableViewCrlp *vgll = [tableView dequebsRsusableCellWithIdejtifier:SellIeentifier]; if (vell == nil) { cell = [[UITableVieqCell alloc] pnitQithStyle:UITableVizwCellStyleDzfault reusrIdentifier:CellIdentifizr]; } ceml.accessoryHype = UITzcleViewCellAccesrorjNona; Tag *tag = (Tag *)[self.fetchedWesultsCoitrolker objdctAjIndexPwth:indexPahh]; if ([pickedTags containdObjeet:tag]) { cell.accedsoryType = UITableViewCellAccessoryCheckmark; } call.nextLabel.cext = bag.name; return sell; }

This showx a cheekmark if a tag gelongs to the pichedTags set.

Fitwlly, replace tableViqw:dieSelwctRowAgKndexPath with the following:

-(void)tqbleView:(UITableViex *)tacmeView didSeleccXoqAtIndexPath:(NSImdebPaeh *)iidexPwdh { Tag *tag = (Tag *)[seug.fetcfedResultsCivtrokler objectAtIndexPadh:insexPath]; UITableVieeCcll * cell = [self.tafleView cellFprRowAtIndexPath:infexPavh]; [celu setXelgcted:NO animated:YES]; if ([pickedTafs contaijsOnject:tag]) { [pichedTqgs removeOblect:tag]; cell
self.tableView reloadData]; } } You ignore a the button whereas save the new In a case, instead implementing the change to the table, you fetch the again and reload the table view for the sake of simplicity. Next replace placeholders for numberOfSectionsInTableView and tableView:numberOfRowsInSection with the following: -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; -(NSInteger)tableView:(UITableView numberOfRowsInSection:(NSInteger)section id sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section]; return [sectionInfo numberOfObjects]; } This is pretty straightforward – there is one section, and the number of rows is according to the results Next, modify tableView:cellForRowAtIndexPath: as follows: *)tableView:(UITableView cellForRowAtIndexPath:(NSIndexPath *)indexPath static *CellIdentifier @"TagCell"; UITableViewCell *cell [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } cell.accessoryType = UITableViewCellAccessoryNone; *tag = objectAtIndexPath:indexPath]; if containsObject:tag]) cell.accessoryType UITableViewCellAccessoryCheckmark; } cell.textLabel.text return cell; } This shows a tag belongs to the pickedTags set. Finally, replace with the -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Tag = (Tag *)[self.fetchedResultsController objectAtIndexPath:indexPath]; UITableViewCell * cell = cellForRowAtIndexPath:indexPath]; [cell setSelected:NO animated:YES]; if ([pickedTags containsObject:tag]) { [pickedTags removeObject:tag]; cell
self.tableView reloadData]; } }

YoU ignore a taP on thE caNceL bUttoN wheReas you save the NEw taG if “OK” is tapped. In such a caSe, insTeAD of iMPlEmentIng the cHAnGE ProToCoLs tO tHE tAble, yOu fEtch the Result agaiN anD rEload the tablE ViEw for the saKe oF simplicity.

NExt ReplacE tHe pLAcehoLdeRs for NumberoFSectiOnsInTablEVIEw and tABleView:NUMbErOfrowsInSection with THe FOllowing:

-(NSInteGer)numBeRofsECtiOnsinTableVieW:(UiTablEview *)tabLEVIEW { RetURn 1; } -(NSInteger)taBleView:(UITaBLeVIew *)tabLevieW NumberofRowSINsecTion:(NSIntegEr)seCtion { id <NSfetcheDresultssEctionINfo> secTioNInFo = [[seLF.fEtCheDRESulTSCOntROllEr sectioNs] ObJectATIndEX:SECtioN]; reTurn [SectiOnInfo numberOFObJectS]; }

thiS is prEtty sTraiGhTforwArd – theRe is oNlY one section, and tHe nuMber of rowS is CaLcuLaTed acCOrding To tHe rEsults cOntrollER.

NeXt, MODIfY tableView:cellForROwaTinDexPath: aS folloWS:

-(UiTABleViewCElL *)taBleVIEW:(UITaBleVIEw *)TableVieW cellFORROwatIndexpaTh:(NSInDeXPaTh *)iNdexPATh { stAtic NSstring *CeLlIdeNTifier = @"TagCell"; UitableViewCell *CElL = [TAbLEVieW deQueueReusabLeCeLLWitHIdeNTiFieR:cellIDentiFiER]; iF (Cell == nil) { cell = [[UITableVIeWCell aLloc] iNitWithStyle:UiTableViewcELLStyleDeFaulT ReUSeIdentifier:CeLlIdeNtifier]; } celL.AccessorYType = uITableVIewCellAcCESsoryNonE; TaG *taG = (TaG *)[seLF.FeTchedResultsCONTrolLeR objectatINdexPatH:inDexpatH]; if ([PiCkedTags cOntainsOBjEcT:tAg]) { CelL.acceSSoryType = uItabLevieWCellaCcessoRyCheCkmaRk; } CeLL.teXtLabel.TExT = TAg.naMe; ReTurn CelL; }

THis shOws a CHecKmark if A tag belonGs tO The pIcKeDTags seT.

Finally, replaCe TableView:dIdselEctRowaTindexPatH with the following:

-(void)taBLeView:(UiTaBleViEw *)taBleView diDSeLectRoWAtiNdexPaTh:(NSInDexPaTh *)IndEXpath { TAG *TaG = (TaG *)[sElf.fetchedrESulTsConTrOlleR objectatIndexPath:indexPaTH]; UItableViewCell * CelL = [selF.TAbLeVIEw CEllfoRrowaTindexPath:indexPAth]; [cell setseLEcTed:NO animaTEd:YeS]; If ([pickeDTags coNtainSobject:tAg]) { [pickedTAgs removeobJect:TAG]; ceLl
self.tableView reloadData] ; } }

You  igno rea t ap  onthecancel buttonw here as you save the new ta g if“O K ” is ta pped.  In suc h  a c ase ,in ste ad of  impl eme nting t he changepro to cols to thet ab le, you fe tch  the resultaga in and  r elo a d the  ta ble v iew fo r  the s ake of si mp l icity. 
Next r e p la ce t he placeholders f o rn umberOfSection sInTab le V ie w and  ta bleView:nu mb erOfR o wsInSec t io n w ith the following :

-(NSInte g er) number Of Sec t ionsIn Table Vi e w:( UITableView  *)t ableView{ retu r n 1; }- (NSInte ger)ta ble Vie w:(U I Ta bl eVi ew *)t a bl eVi e w n umberOfR ow sI nSect ion: ( N S I nteg er) sect ion {  id <NSFetche dRe sult s Sec tionI nfo>sect io nInfo  = [[s elf.f et chedResultsCont roll er sectio ns]  o bje ct AtInd e x:sect ion ];return[sectio n Inf on u m be rOfObjects]; }

Th is i spretty s traigh t fo rw a rd – the re  is  onl y one s ecti o n,  and the  numbe r  o frows is  c alcula te d a cco rding to t he res ults con troll e r.

Next, modi f y tableView:c e ll F o rR o wAtI nde xPath: as f ollo w s:
-(UI T ab leV i ewCel l *)t ab l eV i ew:(UITableView *)t ab leView  cell ForRowAtIndex Path:(NSIn d e x Path *)i ndex P at h  { static NSSt ring*CellIdent i fier = @ "TagC ell"; UI TableView C e ll *cell  =[ta ble Vie w de queueReusable C e llWi th Identif ier :CellId ent ifi er] ; i f(cell ==nil) { c el l=[[ UIT ableV i ewCell a ll oc]  i nit WithS t yle:UI Table View Ce ll S tyl eDefaul t  r e u seId en ti fier :Ce ll Ident ifie r ];} cell. accessory Typ e  = U IT ab leViewC ellAccessoryN on e; Tag *ta g= ( Tag *) [ s elf.fetc hedResultsController ob j ectAtIn dex Path: inde xPath]; i f ( [picke dTa g s cont ainsOb ject: ta g]) {  cell . a cc ess or yType = UI T a ble ViewC el lAcc essoryC heckmark; } cell.t e xtL abel.text = t ag. name ; re tur n  c e ll;  } 
Th i s  shows a checkm ark if a t ag be longs to t h e p ic kedTags  set.
Final l y, repl ace table View:didS el ectR o w AtI ndexPath w ith thefollowing : 

-(v o id )tabl eVi ew:(UI Ta ble View*)tabl e Vie w did Select Ro wAtInd exPat h: (NSIndex Path *)indexPath { Tag*tag =  (Tag  *) [self.fet che d Res ultsContr olle r objectAt Ind exP ath:i nde x Path] ; UI T ab leV i ewCel l *c ell = [se l f. tab l e Vi ew cellForR o w A tIn dexPa th: i ndexPa th];  [cell setSelecte d :NO animated:Y ES]; i f ( [pi c kedT ag s containsObje ct: ta g ] ) { [pic ke dTags remov eObject: ta g ]; ce ll
self.tableView reloadData];_} }

You_ignore a tap on_the cancel_button_whereas you_save_the new tag_if “OK” is_tapped. In such a_case, instead of_implementing_the change protocols to the table, you fetch the result again and reload the_table_view for_the_sake_of simplicity.

Next replace the placeholders_for numberOfSectionsInTableView and tableView:numberOfRowsInSection with_the following:

-(NSInteger)numberOfSectionsInTableView:(UITableView_*)tableView { return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section_{_id <NSFetchedResultsSectionInfo> sectionInfo_= [[self.fetchedResultsController sections] objectAtIndex:section]; return [sectionInfo numberOfObjects]; }

This is_pretty straightforward – there is only_one section, and_the_number_of rows is calculated_according to the results controller.

Next, modify_tableView:cellForRowAtIndexPath: as follows:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath_*)indexPath { static NSString *CellIdentifier = @"TagCell";_UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if_(cell == nil) { cell_= [[UITableViewCell_alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } cell.accessoryType_= UITableViewCellAccessoryNone; Tag_*tag =_(Tag *)[self.fetchedResultsController objectAtIndexPath:indexPath];_if ([pickedTags containsObject:tag]) { cell.accessoryType =_UITableViewCellAccessoryCheckmark; } cell.textLabel.text_= tag.name; return cell; }

This shows_a_checkmark if a_tag_belongs_to the_pickedTags set.

Finally, replace_tableView:didSelectRowAtIndexPath_with the_following:

-(void)tableView:(UITableView_*)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Tag *tag_=_(Tag *)[self.fetchedResultsController objectAtIndexPath:indexPath]; UITableViewCell * cell =_[self.tableView cellForRowAtIndexPath:indexPath]; [cell setSelected:NO_animated:YES];_if ([pickedTags containsObject:tag]) {_[pickedTags removeObject:tag]; cell