0
안녕하세요. 여기에 문제가되는 코드와 내가 받고있는 문제가 있습니다. 컴파일 할 것이지만 경고가 첨부되어 있습니다.NSUserDefaults를 사용하는 데 문제가 있습니다. xcode iphone
또한 forKey 인수를NSNumber
에 대한 메소드 서명이없는
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:highscore forKey:@"HIGHSCORE"]];
, 당신은 누락 :
-(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
최고 점수가 int입니다. –
@BenWilson 수정 된 문제 해결을 참조하십시오. –
완벽하고 항상 [...] 같은 간단한 문제 ... GRRRRR 감사합니다. –