클릭하면 숨겨진 버튼 그룹이 기본 이미지를 표시합니다. 상태를 저장하는 가장 좋은 방법을 알아야하므로 다시 시작할 때 숨겨진보기로 되돌아 가지 않습니다. 이것이 가능한가? 고맙습니다.숨겨진 버튼 저장
-(IBAction)Act1 {
Act1Button.hidden = YES;
}
-(IBAction)De1 {
Act1Button.hidden = NO;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// initialization
}
return self;
}
- (IBAction)savedata:(id)sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:@"myValue" forKey:@"mykey"];
[defaults synchronize];
}
- (void)viewDidLoad
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if (![userDefaults valueForKey:@"mykey"]) {
[userDefaults setValue:@"myValue" forKey:@"mykey"];
NSLog(@"setting value");
}
[userDefaults synchronize];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
'@interface testViewController : UIViewController
{
IBOutlet UIButton *Act1Button;
IBOutlet UIButton *De1Button;
}
@property (retain, nonatomic) IBOutlet UIButton *Act1Button;
@property (retain, nonatomic) IBOutlet UIButton *De1Button;
- (IBAction)Act1;
- (IBAction)De1;
-(IBAction)savedata:(id)sender;
@end`
나는 그것을 읽어 봤는데,하지만 내가 코드를 넣어 필요로하는 곳에 같은 나에게 이해되지 않는다. 예제가 있습니까? 또한 각 단추에 대해이 작업을 수행해야합니까? 다시 한번 감사드립니다. –
누군가가 버튼을 누를 때마다, 당신은 NSUserDefaults에 상태를 작성하고이 [[NSUserDefaults standardUserDefaults] 동기화] ... 영구 메모리에 현재 사용자 기본값을 씁니다 않습니다. 앱이 시작되면 상태를 읽고 그에 따라 행동합니다. 코드를 보지 않고도 더 많은 것을 얻는 것은 어렵습니다. 희망이 도움이됩니다. – pho0
나는 뭔가 잘못하고있다. 내 홈 버튼을 눌러 앱을 다시 시작하면 저장하고 다시로드 할 수 있지만 메뉴 화면으로 돌아 가면 변경 사항이 느슨합니다. 코드를 맨 위에 추가했습니다. 네가 나를 도울 수 있기를 정말로 바라고있어! 다시 한번 감사드립니다. –