[Code Note] account, password, and code note
I ,.
2. Engineering Drawing.
3. Code.
RegisViewController. h
#import <UIKit/UIKit.h>@interface RegisViewController : UIViewController@end
RegisViewController. m
// Registration page # 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 = @ "register"; [self initView];}-(void) initView {accountField = [[UITextField alloc] initWithFrame: CGRectMake (50,100,200, 40)]; [accountField setBackgroundColor: [UIColor redColor]; [accountField setPlaceholder: @ "enter an account"]; [accountField setKeyboardType: UIKeyboardTypeNumberPad]; [accountField setClearsContextBef OreDrawing: YES]; [self. view addSubview: accountField]; passField = [[UITextField alloc] initWithFrame: CGRectMake (50,160,200, 40)]; [passField setBackgroundColor: [UIColor redColor]; [passField setPlaceholder: @ "Enter Password"]; [passField setKeyboardType: UIKeyboardTypeNumberPad]; [passField setClearsContextBeforeDrawing: YES]; [self. view addSubview: passField]; UIButton * registeBut = [UIButton buttonWithType: UIB UttonTypeRoundedRect]; registeBut. backgroundColor = [UIColor greenColor]; registeBut. frame = CGRectMake (70,220,100, 40); [registeBut setTitle: @ "register" forState: UIControlStateNormal]; [registeBut addTarget: self action: @ selector (resis) forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: registeBut];} // when registering, save the account and password to the local device. -(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 didreceivemorywarning]; // Dispose of any resources that can be recreated .}
LoginViewController. h
#import <UIKit/UIKit.h>@interface LoginViewController : UIViewController@end
LoginViewController. m
// Login page # import "LoginViewController. h "@ class RegisViewController; @ interface LoginViewController () {UITextField * accountField; UITextField * passField;} @ end @ implementation LoginViewController-(id) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) handle {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 = @ "login"; [self initView];}-(void) initView {accountField = [[UITextField alloc] initWithFrame: CGRectMake (50,100,200, 40)]; [accountField setBackgroundColor: [UIColor redColor]; [accountField setKeyboardType: UIKeyboardTypeNumberPad]; [accountField Expiration: 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: @ "login" forState: UIControlStateNormal]; [loginBut addTarget: self action: @ selector (login) forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: loginBut];}-(void) login {[self. navigationController popViewControllerAnimated: YES];}