ios - Accessing dictionaries in PList for UITableView -


i'd create simple reference app lists group of people, job title, , portrait. have far list of people , job title. works alright, think should have done differently.

from reading other posts, suppose should using dictionaries. how plist looks:

my plist

and how important bits of code look:

@implementation rootviewcontroller  @synthesize staffarray, subtitlearray;   - (void)viewdidload {     [super viewdidload];     nsstring* path = [[nsbundle mainbundle] pathforresource:@"staffdata" oftype:@"plist"];     nsdictionary *dict = [nsdictionary dictionarywithcontentsoffile:path];     nsmutablearray *tmpnamearray = [dict objectforkey:@"root"];     self.staffarray = [[nsmutablearray alloc] initwitharray:tmpnamearray copyitems:yes];     nsmutablearray* tmpsubtitlearray = [dict objectforkey:@"subs"];     self.subtitlearray = [[nsmutablearray alloc] initwitharray:tmpsubtitlearray copyitems:yes]; }  - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return [staffarray count]; }  // customize appearance of table view cells. - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell";  uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) {     cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier] autorelease]; }  // configure cell. cell.textlabel.text = [staffarray objectatindex:indexpath.row]; cell.detailtextlabel.text = [subtitlearray objectatindex:indexpath.row]; return cell; } 

using 2 arrays kind of defeats purpose of oop, think, because in case people aren't connected job titles; happen in same order. i'd create example:

array called jonas, first value = job title, second value = pathtoimage.png.

another array called andreas, etc etc etc.

what do?

i think start, design lacks "employee" object, has data members "name", "jobtitle", etc... after have set up, create array of people , take whatever need there, index.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -