用xib登陸

#import <UIKit/UIKit.h>

@interface loginVIewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *userNameLabel;

@property (strong, nonatomic) IBOutlet UILabel *userPasswordLabel;
@property (strong, nonatomic) IBOutlet UITextField *userNameTextfield;
@property (strong, nonatomic) IBOutlet UITextField *userPasswordTextfield;
- (IBAction)loginPressBtn:(UIButton *)sender;
- (IBAction)registerPressBtn:(UIButton *)sender;
@end

#import "loginVIewController.h"
#import "ViewController.h"

@interface loginVIewController ()
{
    NSMutableArray *Localarray;
}
@end

@implementation loginVIewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //datasource;
    Localarray = [[NSMutableArray alloc]init];
}


//鍵盤響應
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [_userNameTextfield resignFirstResponder];
    
    [_userPasswordTextfield resignFirstResponder];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)loginPressBtn:(UIButton *)sender {
    
    NSArray *array = [[NSUserDefaults standardUserDefaults]objectForKey:@"dataLocal"];
    NSString *userName = _userNameTextfield.text;
    NSString *userPass = _userPasswordTextfield.text;
    
    for (NSDictionary *dic in array)
    {
        NSString *passName = [dic objectForKey:userPass];
        if ([passName isEqualToString:userName]== YES){
            NSLog(@"登錄成功");
            ViewController *vc = [[ViewController alloc]init];
            [self presentViewController:vc animated:YES completion:^{
                vc.view.backgroundColor = [UIColor whiteColor];//登陸成功跳轉
            }];
        }else
        {
            NSLog(@"登錄失敗");
        }
        NSLog(@"dic == %@",dic);
    }
    
    
}
//本地存取 註冊帳戶
- (IBAction)registerPressBtn:(UIButton *)sender {
    
    NSString *userName = _userNameTextfield.text;
    NSString *userPassword = _userPasswordTextfield.text;
    NSDictionary *dic  = @{userPassword:userName};
    [Localarray addObject:dic];
    [[NSUserDefaults standardUserDefaults]setObject:Localarray forKey:@"dataLocal"];
    [[NSUserDefaults standardUserDefaults]synchronize];
}
@end

相關文章
相關標籤/搜索