0

現在、iPhoneでクイズゲームを作成しようとしているので、チュートリアルを見ましたが、xcodeが私のplistなどを理解していないようです:実行するとラベルが空白になります:.mファイルで:

- (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);

}

もちろん、すべてではなく、関連するコードを付けただけです。誰か助けてください??

4

1 に答える 1

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;
    }
}

それが役立つかどうか教えてください!

于 2013-02-12T20:31:36.040 に答える