iOS 계 정,비밀번호 기억 기능 구현

본 논문 의 사례 는 안 드 로 이 드 구 궁 격 사진 전시 의 구체 적 인 코드 를 공유 하여 여러분 께 참고 하 시기 바 랍 니 다.구체 적 인 내용 은 다음 과 같 습 니 다.
효과 도


2.공정 도

코드
RegisViewController.h

#import <UIKit/UIKit.h>

@interface RegisViewController : UIViewController

@end

 RegisViewController.m

 //    
#import "RegisViewController.h"
#import "LoginViewController.h"

@interface RegisViewController ()
{
  UITextField *accountField;
  UITextField *passField;
}

@end

@implementation RegisViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  if (self) {
    // Custom initialization
  }
  return self;
}

- (void)viewDidLoad
{
  [super viewDidLoad];
  // Do any additional setup after loading the view.
  
  self.title=@"  ";
  
  [self initView];
  
}
-(void)initView
{
  accountField=[[UITextField alloc]initWithFrame:CGRectMake(50, 100, 200, 40)];
  [accountField setBackgroundColor:[UIColor redColor]];
  [accountField setPlaceholder:@"     "];
  [accountField setKeyboardType:UIKeyboardTypeNumberPad];
  [accountField setClearsContextBeforeDrawing:YES];
  [self.view addSubview:accountField];
  
  
  passField=[[UITextField alloc]initWithFrame:CGRectMake(50, 160, 200, 40)];
  [passField setBackgroundColor:[UIColor redColor]];
  [passField setPlaceholder:@"     "];
  [passField setKeyboardType:UIKeyboardTypeNumberPad];
  [passField setClearsContextBeforeDrawing:YES];
  [self.view addSubview:passField];
  
  
  UIButton *registeBut=[UIButton buttonWithType:UIButtonTypeRoundedRect];
  registeBut.backgroundColor=[UIColor greenColor];
  registeBut.frame=CGRectMake(70, 220, 100, 40);
  [registeBut setTitle:@"  " forState:UIControlStateNormal];
  [registeBut addTarget:self action:@selector(resis) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:registeBut];

}

//     ,   ,       。
-(void)resis
{

  NSUserDefaults *defaut=[NSUserDefaults standardUserDefaults];
  [defaut setObject:accountField.text forKey:@"account"];
  [defaut setObject:passField.text forKey:@"password"];
  [defaut synchronize];
  
  LoginViewController *login=[[LoginViewController alloc]init];
  [self.navigationController pushViewController:login animated:YES];
    
  
}
- (void)didReceiveMemoryWarning
{
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
}

LoginViewController.h

#import <UIKit/UIKit.h>

@interface LoginViewController : UIViewController

@end

 LoginViewController.m

 //    
#import "LoginViewController.h"

@class RegisViewController;
@interface LoginViewController ()
{
  UITextField *accountField;
  UITextField *passField;
}
@end

@implementation LoginViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  if (self) {
    // Custom initialization
  }
  return self;
}

- (void)viewDidLoad
{
  [super viewDidLoad];
  // Do any additional setup after loading the view.
  self.title=@"  ";
  
  [self initView];
  
}
-(void)initView
{
  accountField=[[UITextField alloc]initWithFrame:CGRectMake(50, 100, 200, 40)];
  [accountField setBackgroundColor:[UIColor redColor]];
  [accountField setKeyboardType:UIKeyboardTypeNumberPad];
  [accountField setClearsContextBeforeDrawing:YES];
  [accountField setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"account"]];
  [self.view addSubview:accountField];
  
  
  passField=[[UITextField alloc]initWithFrame:CGRectMake(50, 160, 200, 40)];
  [passField setBackgroundColor:[UIColor redColor]];
  [passField setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"password"]];
  [passField setKeyboardType:UIKeyboardTypeNumberPad];
  [passField setClearsContextBeforeDrawing:YES];
  [self.view addSubview:passField];
  
  
  UIButton *loginBut=[UIButton buttonWithType:UIButtonTypeRoundedRect];
  loginBut.backgroundColor=[UIColor greenColor];
  loginBut.frame=CGRectMake(70, 220, 100, 40);
  [loginBut setTitle:@"  " forState:UIControlStateNormal];
  [loginBut addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:loginBut];
  
  
}
-(void)login
{
  [self.navigationController popViewControllerAnimated:YES];
}

이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기