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;
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。