0

嗨,这里是有问题的代码和我遇到的问题,它会编译但附有警告,我已经突出显示。

-(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 
4

1 回答 1

3

你的问题在这里:

[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:highscore forKey:@"HIGHSCORE"]];

没有方法签名NSNumber也需要一个 forKey 参数,你缺少一个括号来关闭 NSNumber numberwithint,改成这个来解决问题:

[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:highscore] forKey:@"HIGHSCORE"];
于 2012-06-19T15:19:40.253 回答