用歸檔解檔實現簡單登錄

一.ViewController.h中代碼程序員

//
//  ViewController.h
//  歸檔登錄
//
//  Created by 非凡程序員 on 15/6/12.
//  Copyright (c) 2015年 wzhen. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UITextField *name;
@property (weak, nonatomic) IBOutlet UITextField *passworld;

@property (weak, nonatomic) IBOutlet UILabel *reminder;

- (IBAction)enter:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *card;



@end

二.ViewController.m中代碼atom

//
//  ViewController.m
//  歸檔登錄
//
//  Created by 非凡程序員 on 15/6/12.
//  Copyright (c) 2015年 wzhen. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

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

- (IBAction)enter:(id)sender {
    NSMutableData *mudate=[[NSMutableData alloc]init];//可變文件留,分配內存
    NSKeyedArchiver *archiver=[[NSKeyedArchiver alloc]initForWritingWithMutableData:mudate];
    NSString *setname=@"wangzhen";
    NSString *setpassworld=@"888888";
    [archiver encodeObject:setname forKey:@"setname"];
    [archiver encodeObject:setpassworld forKey:@"setpassworld"];
    [archiver finishEncoding];
    [mudate writeToFile:@"/Users/feifanchengxuyuan/Desktop/enter.txt" atomically:YES];
    NSKeyedUnarchiver *unarchiver=[[NSKeyedUnarchiver alloc]initForReadingWithData:mudate];
    NSString *getname=[unarchiver decodeObjectForKey:@"setname"];
    NSString *getpassworld=[unarchiver decodeObjectForKey:@"setpassworld"];
    if ([_name.text isEqualToString:getname]) {
        if ([_passworld.text isEqualToString:getpassworld]) {
            [_reminder setText:@"登錄成功"];
            NSLog(@"登陸成功");
  //        [_card setTitle:@"登陸成功,進入下一個連接頁面" forState:UIControlStateNormal];
        }
        else{
            [_reminder setText:@"抱歉,您的登陸名和密碼不匹配"];
            
        }
    }
    else{
        [_reminder setText:@"抱歉,您的登陸名不存在"];

    }
    NSLog(@"name:%@,passworld:%@",getname,getpassworld);
    
}
@end

三.隱藏顯示的密碼spa

勾選右側中的Secure Text Entry
code

相關文章
相關標籤/搜索