我想將我的遊戲部分的分數傳遞給記分板。但是,我似乎無法做到這一點。這是我的代碼,在我的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