iphone - UITableView (not using Navigation Template) getting specific data from plist -


i'm using example on page 210 of beginning iphone development (exploring iphone sdk) book , it's similar want specific example complicated using sections in tableview. have specific hierarchy in plist...

root  ---- dictionary         rows  ---- array                 item 0- dictionary                         fullname  ---- string                         address   ---- string                 item 1   ---- dictionary                         fullname  ---- string                         address   ---- string 

so have uitableview takes small portion of view on "screen" rest of view has other elements chose nut use navigation template.

the code i'm using doesn't match because i'm not clear on calling fields.

can show me simple example how list "firstnames" in table. if wrong plist please let me know change.

in nutshell want loop through item # dictionaries list first names. design similar contact list, not contact list.

right i'm using code displays word "rows" changed word rows rows1 in plist , shows it's grabbing "array item". hope said right.

-(void)viewdidload {         nsstring *path = [[nsbundle mainbundle] pathforresource:@"data" oftype:@"plist"];      nsdictionary *dict = [[nsdictionary alloc] initwithcontentsoffile:path];     self.names = dict;     [dict release];      nsarray *array = [[names allkeys] sortedarrayusingselector:@selector(compare:)];     self.listdata = array;      [super viewdidload]; } 

 

-(nsinteger)tableview:(uitableview *)tableview  numberofrowsinsection:(nsinteger)section {     return [self.listdata count]; }  - (uitableviewcell *)tableview:(uitableview *)tableview          cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *simpletableidentifier = @"identifier";      uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier];     if (cell == nil) {         cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:simpletableidentifier] autorelease];     }      nsuinteger row = [indexpath row];     cell.textlabel.text = [listdata objectatindex:row];     return cell; } 

i've scoured web days trying find simple example uses plist hierarchy list items in table not part of navigation template.

thanks much

i wrote example code, address book. reads data plist.

the plist:

<?xml version="1.0" encoding="utf-8"?> <!doctype plist public "-//apple//dtd plist 1.0//en" "http://www.apple.com/dtds/propertylist-1.0.dtd"> <plist version="1.0"> <array>     <dict>         <key>name</key>         <string>vikingo</string>         <key>familyname</key>         <string>segundo</string>         <key>street</key>         <string>avenida roca y coranado</string>         <key>number</key>         <integer>20</integer>         <key>city</key>         <string>santa cruz de la sierra</string>         <key>province</key>         <string>santa cruz</string>         <key>country</key>         <string>bolivia</string>         <key>pictureurl</key>         <string>vikingosegundo.png</string>     </dict>     <dict>         <key>name</key>         <string>santa</string>         <key>familyname</key>         <string>claus</string>         <key>street</key>         <string>avenida roca y coranado</string>         <key>number</key>         <integer>20</integer>         <key>city</key>         <string>santa cruz de la sierra</string>         <key>province</key>         <string>santa cruz</string>         <key>country</key>         <string>finland</string>         <key>pictureurl</key>         <string>robot-santa.png</string>     </dict> </array> </plist> 

read plist:

nsstring* plistpath = [[nsbundle mainbundle] pathforresource:@"contacts" oftype:@"plist"]; contacts = [[nsarray arraywithcontentsoffile:plistpath] retain]; 

display contacts in tableview:

- (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     return 1; }   // customize number of rows in table view. - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {     return [contacts 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:uitableviewcellstyledefault reuseidentifier:cellidentifier] autorelease];     }      nsdictionary *dict = [contacts objectatindex:indexpath.row];     cell.textlabel.text = [nsstring stringwithformat:@"%@ %@", [dict objectforkey:@"name"], [dict objectforkey:@"familyname"]];      return cell; }  - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {       detailcontactviewcontroller *detailviewcontroller = [[detailcontactviewcontroller alloc] initwithnibname:@"detailcontactview" bundle:nil];     detailviewcontroller.contact = [contacts objectatindex:indexpath.row];     // ...     // pass selected object new view controller.     [self.navigationcontroller pushviewcontroller:detailviewcontroller animated:yes];      [detailviewcontroller release];  } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -