AppDelegate 代码
-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ViewController *vc = [ViewController new];
vc.dictUserInfo=@{@"User":[[NSUserDefaults standardUserDefaults] objectForKey:@"User"],
@"Pwd" : [[NSUserDefaults standardUserDefaults] objectForKey:@"Pwd"],
@"IP" : [[NSUserDefaults standardUserDefaults] objectForKey:@"IP"]
};
self.window.rootViewController = vc;
return YES;
}
ViewController.m 代码
- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[UIColor whiteColor]; self.alertView = [[UIAlertView alloc]initWithTitle:@"失败" message:@"你好" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; [self.view addSubview:self.alertView]; self.txtIP.delegate = self; self.txtUser.delegate = self; self.txtPwd.delegate =self; }
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.txtUser.text =self.dictUserInfo[@"User"];
self.txtPwd.text = self.dictUserInfo[@"Pwd"];
self.txtIP.text = self.dictUserInfo[@"IP"];
}
-
(IBAction)btnLoginClick:(id)sender {
NSString *user =self.txtUser.text;
NSString *pwd = self.txtPwd.text;
NSString *address = self.txtIP.text;if (user.length>0&&pwd.length>0&&address.length>0) { [[NSUserDefaults standardUserDefaults] setObject:user forKey:@"User"]; [[NSUserDefaults standardUserDefaults] setObject:pwd forKey:@"Pwd"]; [[NSUserDefaults standardUserDefaults] setObject:address forKey:@"IP"]; } else { self.alertView.message=@"参数输入错误!"; [self.alertView show]; }
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}