嗨,这里是有问题的代码和我遇到的问题,它会编译但附有警告,我已经突出显示。
-(void)viewdidloader
{
highscore = [[[NSUserDefaults standardUserDefaults] objectForKey:@"HIGHSCORE"]integerValue];
}
(void) differnt void
if (score>=highscore)
{
highscore = score;
//问题从这条线开始
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:highscore forKey:@"HIGHSCORE"]];
highscorelabel.text = [NSString stringWithFormat:@"%i",highscore ];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"NEW HIGH SCORE" message:[NSString stringWithFormat: @"Well done you got a new high score Level : %d and scored %i points" ,fred,score ] delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
[alert release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You Lose" message:[NSString stringWithFormat: @"Unlucky you only made it to Level : %d and scored %i points" ,fred,score ] delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
[alert release];
}
Issues
NSNumber may not respond to +number:forkey
(message without a matching method signature will be assumed to return "ID" and accept '' as an argument)
NSUserdefaukts may not respond to -setobject