单击时我有一组按钮被隐藏,显示底层图像。我需要知道保存状态的最佳方法,以便在重新启动时它们不会恢复到未单击的视图。这可能吗?谢谢你。
-(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`