ios - .plist access array of dictionaries? -
my .plist starts array root , has multiple keys of dictionaries containing 6 items each.
- (void)viewdidload { nsstring *path = [[nsbundle mainbundle] pathforresource:@"questions" oftype:@"plist"]; self.questions = [nsarray arraywithcontentsoffile:path]; nsdictionary *firstquestion = [self.questions objectatindex:0]; self.questionlabel.text = [firstquestion objectforkey:@"questiontitle"]; [self.ansone settitle:[firstquestion objectforkey:@"a"] forstate:uicontrolstatenormal]; [self.anstwo settitle:[firstquestion objectforkey:@"b"] forstate:uicontrolstatenormal]; [self.ansthree settitle:[firstquestion objectforkey:@"c"] forstate:uicontrolstatenormal]; [self.ansfour settitle:[firstquestion objectforkey:@"d"] forstate:uicontrolstatenormal];
but load blank labels, here's xml of .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>questiontitle</key> <string>which of next probes accomplish highest penetration?</string> <key>a</key> <string>5.0 mhz</string> <key>b</key> <string>4.0 mhz</string> <key>c</key> <string>3.4 mhz</string> <key>d</key> <string>1.0 mhz</string> <key>questionanswer</key> <string>d</string> </dict> <dict> <key>questiontitle</key> <string></string> <key>a</key> <string></string> <key>b</key> <string></string> <key>c</key> <string></string> <key>d</key> <string></string> <key>questionanswer</key> <string></string> </dict> <dict> <key>questiontitle</key> <string></string> <key>a</key> <string></string> <key>b</key> <string></string> <key>c</key> <string></string> <key>d</key> <string></string> <key>questionanswer</key> <string></string> </dict> </array> </plist>
i next tutorial , many other people facing issue, can point me in right direction, or prepare code me please?
thanks in advance.
my app same thing yours trying except plist root dictionary instead of array.
instead of:
self.questions = [nsarray arraywithcontentsoffile:path];
use:
nsdictionary* questions = [nsdictionary dictionarywithcontentsoffile:path];
and question want to, use:
nsdictionary *firstquestion = [nsdictionary dictionarywithdictionary:[questions objectforkey:[nsstring stringwithformat:@"0"]]];
ios objective-c
No comments:
Post a Comment