ユーザーが[覚えている]チェックボックスをオンにしたときにパスワードを保存したい。私はこのようなコードを持っています:これは正しいですか?
Appdelegate.mで
@property(strong,nonatomic)NSString *savedno;
.mファイル内
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.navcontrol =[[UINavigationController alloc]initWithRootViewController:self.viewController ];
self.window.rootViewController = self.navcontrol;
[self.window makeKeyAndVisible];
self.savedno=[[NSUserDefaults standardUserDefaults]objectForKey:@"pass"];
if(savedno==nil)
{
NSDictionary *saveDict=[NSDictionary dictionaryWithObject:savedno forKey:@"pass"];
[[NSUserDefaults standardUserDefaults]registerDefaults:saveDict];
}
return YES;
}
- (void)applicationWillTerminate:(UIApplication *)application
{
/*
Called when the application is about to terminate.
Save data if appropriate.
See also applicationDidEnterBackground:.
*/
NSUserDefaults *userdefault=[NSUserDefaults standardUserDefaults];
[userdefault setObject:savedno forKey:@"pass"];
}
//ViewDelegate.mファイル
//チェックボックスのイベント
-(IBAction)check:(id)sender
{
if (checkboxSelected == 0)
{
[checkboxButton setSelected:YES];
[checkboxButton setImage:[UIImage imageNamed:@"checkbox-checked.png"]forState:UIControlStateNormal];
// userdefault=[NSUserDefaults standardUserDefaults];
// [userdefault setObject:user.text forKey:@"user"];
// [userdefault setObject:pass.text forKey:@"pass"];
self.callno=pass.text;
pass.text=self.callno;
AppDelegate *appdelegate=[[UIApplication sharedApplication]delegate];
appdelegate.savedno=self.callno;
NSLog(@"Data saved");
checkboxSelected = 1;
}
else
{
[checkboxButton setSelected:NO];
[checkboxButton setImage:[UIImage imageNamed:@"checkbox.png"]forState:UIControlStateNormal];
user.text=@"";
pass.text=@"";
checkboxSelected = 0;
}
}
- (void)viewDidLoad
{
user.clearButtonMode=UITextFieldViewModeWhileEditing;
AppDelegate *appdel=[[UIApplication sharedApplication]delegate];
if([user.text isEqualToString:@"bhoomi"])
{
pass.text=appdel.savedno;
}
[super viewDidLoad];
checkboxSelected = 0;
// Do any additional setup after loading the view, typically from a nib.
}
`