저는 아주 간단한 iPhone 응용 프로그램을 만들고 있습니다. 그러나 NSUserDefaults를 영구 저장하지 못합니다. 데이터 쓰기 및 검색은 문제가 아닙니다.보기를 전환하고 응용 프로그램을 닫거나 열어 본 후에도 데이터를 저장하고 명령으로 검색 할 수 있으며 데이터가 검색됩니다. 벌금. 문자열이 키에 제대로 저장된 것처럼 나타납니다. 그러나 멀티 태스킹 트레이에서 응용 프로그램을 종료하고 다시 시작하면 설정이 더 이상 저장되지 않으며 응용 프로그램이 처음처럼 부팅됩니다. 나는 초보자 프로그래머이다. 그래서 아마 내 입장에서는 어리석은 실수 일 것이다.NSUserDefaults가 영구적으로 저장되지 않습니다
NSUserDefaults *soundOptions = [NSUserDefaults standardUserDefaults];
NSString *savedSoundSettings = [soundOptions stringForKey:@"SoundKey"];
if (savedSoundSettings == @"SoundsON")
{
[optionsSoundBox setCenter:CGPointMake(280, optionsSoundBox.center.y)];
}
if (savedSoundSettings == @"SoundsOFF")
{
[optionsSoundBox setCenter:CGPointMake(200, optionsSoundBox.center.y)];
}
난 정말 어떤 도움이 줄 수있는 감사 : 내가있는 viewDidLoad에서 문자열을 검색
if (optionsSoundBox.center.x >= 240)
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.2];
self.soundOnLabel.alpha = 1;
self.soundOffLabel.alpha = 0;
[UIView commitAnimations];
NSUserDefaults *soundOptions = [NSUserDefaults standardUserDefaults];
[soundOptions setObject:@"SoundsON" forKey:@"SoundKey"];
[soundOptions synchronize];
}
if (optionsSoundBox.center.x < 240)
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.2];
self.soundOnLabel.alpha = 0;
self.soundOffLabel.alpha = 1;
[UIView commitAnimations];
NSUserDefaults *soundOptions = [NSUserDefaults standardUserDefaults];
[soundOptions setObject:@"SoundsOFF" forKey:@"SoundKey"];
[soundOptions synchronize];
}
가이 같은 시작할 준비가 될 것입니다, 그래서 다음은
는 절약의 모습입니다