2013-02-12 3 views
0

나는 현재 을 시도하여 iphone에서 퀴즈 게임을 만들었습니다. 자습서를 보았지만 xcode가 내 plist를 이해하지 못하는 것 같습니다. 실행할 때 내 레이블이 비어 있습니다. 내 .m 파일 :plist에서 정보를 얻으십시오

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the 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 over 
    } 
} 


- (IBAction)buttonPressedA:(id)sender{ 
if ([self.Answear isEqualToString:@"A"]) { 
    numCorrect++; 
    NSLog(@"%d", numCorrect); 

} 

물론 나는 관련 코드를 넣었지만 모든 코드를 넣지 않았습니다. 누군가 도움을 줄 수 있습니까 ??

+0

tempDict를 기록하면 어떻게됩니까? – rdelmar

+0

어떻게하면됩니까? (빠른 답변 감사합니다!) – lea51294

+0

NSLog (@ "% @", tempDict); – rdelmar

답변

0

가 여기 내 checkForPlist 방법이다하는 BOOL을 반환하고 PLIST 실행 가치가있을 수 있으므로 존재하는 경우는 NSDictionary을 채 웁니다 :

-(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); 
     return NO; 
    } 
    else 
    { 
     NSLog(@"Plist exists - %@", [self.plistDictionary objectForKey:@"LastUpdated"]); 
     return YES; 
    } 
} 

가 도움이되는지 알려주세요!

+0

.h 파일에 무엇을 넣어야합니까? (죄송합니다, 당신에게 분명하지만 확실하게 시작했습니다.) – lea51294

+0

문제 없습니다 - plistDictionary라는 .h 파일에 NSDictionary를 선언해야합니다. 그 밖의 모든 것은이 메소드의 범위에서 선언되며 외부에서는 불필요합니다. – TiernanKennedy

+0

또한 plist 파일 이름에 공백을 생략 할 수 있습니다. – TiernanKennedy

관련 문제