我想将我的游戏部分的分数传递给记分板。但是,我似乎无法做到这一点。这是我的代码,在我的GameViewController
。无法在两个视图控制器之间传递数据
- (void)gameHasEnded {
ScoreViewController *scoreVC = [[ScoreViewController alloc] initWithNibName:@"ScoreVC" bundle:nil];
scoreVC.score = scoreAsString;
NSLog(@"%@",scoreVC.score);
[self performSegueWithIdentifier:@"continueToScore" sender:self];
}
这是我的代码在我的ScoreViewController
。
- (void)viewDidLoad {
[super viewDidLoad];
self.scoreLabel.text = scoreString;
NSLog(@"Score = %d", self.score);
}
在日志中它显示正确的分数,然后它执行segue。但是,一旦在ScoreViewController
它给出一个空值。我提到Passing Data between View Controllers但它不适合我。为什么它不适合我?代码有什么问题,或者我错过了代码中的某些内容?
使用segue.destinationViewController可能会更好。 – Lucifron