ios - Retrive information from plist -
i'm trying create quiz game on iphone saw tutorial seems xcode doesn't understand plist or something: labels blank when run it: in .m file:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view. questionnumber = 0; nsstring * path = [[nsbundle mainbundle] pathforresource:@"propriety list" oftype:@"plist"]; if (path) { nsdictionary *tempdict = [[nsdictionary alloc] initwithcontentsoffile: path]; self.question = [tempdict objectforkey:@"root"];} currentquestion = -1; } -(void) shownextquestion { currentquestion++; if (currentquestion < [self.question count]) { nsdictionary *nextquestion = [self.question objectatindex:currentquestion]; self.answear = [nextquestion objectforkey:@"questionanswear"]; self.labelquestiontitle.text = [nextquestion objectforkey:@"questiontitle"]; self.labelansweara.text = [nextquestion objectforkey:@"a"]; self.labelanswearb.text = [nextquestion objectforkey:@"b"]; self.labelanswearc.text = [nextquestion objectforkey:@"c"]; self.labelansweard.text = [nextquestion objectforkey:@"d"]; self.labelansweare.text = [nextquestion objectforkey:@"e"]; } else { // game on } } - (ibaction)buttonpresseda:(id)sender{ if ([self.answear isequaltostring:@"a"]) { numcorrect++; nslog(@"%d", numcorrect); }
of course of study i've set on related codes , not of them. can help please??
here checkforplist method, returns bool , fills nsdictionary if plist exists worth running:
-(bool) checkforplist { nsstring *errordesc = nil; nspropertylistformat format; nsstring *plistpath; nsstring *rootpath = [nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes) objectatindex:0]; plistpath = [rootpath stringbyappendingpathcomponent:@"testplist.plist"]; if (![[nsfilemanager defaultmanager] fileexistsatpath:plistpath]) { plistpath = [[nsbundle mainbundle] pathforresource:@"testplist" oftype:@"plist"]; } nsdata *plistxml = [[nsfilemanager defaultmanager] contentsatpath:plistpath]; self.plistdictionary = (nsmutabledictionary *)[nspropertylistserialization propertylistfromdata:plistxml mutabilityoption:nspropertylistmutablecontainersandleaves format:&format errordescription:&errordesc]; if (!self.plistdictionary) { nslog(@"error reading plist: %@, format: %d", errordesc, format); homecoming no; } else { nslog(@"plist exists - %@", [self.plistdictionary objectforkey:@"lastupdated"]); homecoming yes; } }
let me know if helps!
ios cocoa-touch plist
No comments:
Post a Comment