我正在開發一款使用遊戲中心的應用程序,但我遇到問題。我希望玩家將他們的分數提交給排行榜,以便他們可以挑戰朋友。這是NSString得分的代碼。將NSString轉換爲Int - 遊戲中心
-(IBAction)gasPedalPressed:(id)sender {
double noSeconds = (double) [self.startDate timeIntervalSinceNow] * -1000;
NSString *reactionTime= [[NSString alloc] initWithFormat:@"Good Job! You're reaction time is %1.0f Ms. Let's see if you can do better...", noSeconds];
NSString *time= [[NSString alloc] initWithFormat:@"%1.0f Ms", noSeconds];
if(greenLightOn == 0)
reactionTime = @"Slow down! You have to wait for the green light. Let's see if you can do better...";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Reaction Time" message:reactionTime
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
,這就是我想,遵守:
-(IBAction)submitscore:(id)sender {
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:@"1234567890"];
scoreReporter.value = score.text;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error !=nil) {;
NSLog(@"failed sub score");
} else {
NSLog(@"submitted score");
}
}
];
}
請幫助!
不是' - [NSString intValue]'爲你工作嗎? – Costique
@Costique我加了這個NSString * myString = [NSString stringWithString:@「time」]; scoreInt = [myString intValue];但它仍然不會工作 – RafeeJ