我目前正在尝试在 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);
}
当然,我只是放了相关代码,而不是全部。有人可以帮忙吗?