로그 인
6283 단어 QQ 로그 인
//
// ViewController.h
// QQRegLogin
//
// Created by jabez.huang on 15/6/15.
// Copyright (c) 2015 jabez.huang. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *QQNumber;
@property (weak, nonatomic) IBOutlet UITextField *QQPassword;
@property (weak, nonatomic) IBOutlet UILabel *ResultMessage;
- (IBAction)Login:(id)sender;
@end
2. ViewController. m 중 코드
//
// ViewController.m
// QQRegLogin
//
// Created by jabez.huang on 15/6/15.
// Copyright (c) 2015 jabez.huang. All rights reserved.
//
#import "ViewController.h"
#define PATH @"/Users/feifanchengxuyuan/Desktop/QQNumberFile.plist"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// QQ
_QQPassword.secureTextEntry = YES;
// 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)Login:(id)sender {
// : , 。
NSString *qqNumber = _QQNumber.text;
NSString *qqPassword = _QQPassword.text;
// QQ 5 , QQ 6
if( ([qqNumber length] > 4 ) && ([qqPassword length] > 5)){
// NSFileManager
NSFileManager *fileManager = [NSFileManager defaultManager];
//
NSData *data = [fileManager contentsAtPath: PATH];
//
NSKeyedUnarchiver *unArchiver = [[NSKeyedUnarchiver alloc]initForReadingWithData: data];
// key QQ
NSDictionary *dict = [unArchiver decodeObjectForKey: @"QQ"];
// qqNumber qqPassword ,qqNumber qqPassword ,
if ( [dict[qqNumber] isEqualToString: qqPassword] ){
_ResultMessage.text = @" !";
}else{
_ResultMessage.text = @"QQ QQ !";
}
}else{
_ResultMessage.text = @"QQ QQ !";
}
}
@end
3. RegViewController. h
//
// RegViewController.h
// QQRegLogin
//
// Created by jabez.huang on 15/6/15.
// Copyright (c) 2015 jabez.huang. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface RegViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *QQRegNumber;
@property (weak, nonatomic) IBOutlet UITextField *QQRegPassword;
@property (weak, nonatomic) IBOutlet UITextField *QQSureRegPassword;
@property (weak, nonatomic) IBOutlet UILabel *ResultMessage;
- (IBAction)QQRegButton:(id)sender;
@end
4. RegViewController. m
//
// RegViewController.m
// QQRegLogin
//
// Created by jabez.huang on 15/6/15.
// Copyright (c) 2015 jabez.huang. All rights reserved.
//
#import "RegViewController.h"
#define PATH @"/Users/feifanchengxuyuan/Desktop/QQNumberFile.plist"
@interface RegViewController ()
@end
@implementation RegViewController
- (void)viewDidLoad {
[super viewDidLoad];
// QQ ,
_QQRegNumber.enabled = NO;
// QQ
_QQRegPassword.secureTextEntry = YES;
// QQ
_QQSureRegPassword.secureTextEntry = YES;
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)QQRegButton:(id)sender {
//QQ QQ 6
if( [_QQRegPassword.text length] < 6 || [_QQSureRegPassword.text length] < 6){
_ResultMessage.text = @" 6 ";
}else if( ![_QQRegPassword.text isEqualToString: _QQSureRegPassword.text ]){ //
_ResultMessage.text = @" !";
}else{
// QQ
// : , QQ
NSDate *date = [NSDate date];
NSInteger QQNumber = (long)[date timeIntervalSince1970];
// QQ QQ
_QQRegNumber.text = [NSString stringWithFormat: @"%li", QQNumber];
// , ,
// NSFileManager
NSFileManager *fileManager = [NSFileManager defaultManager];
// NSData
NSData *data = [fileManager contentsAtPath: PATH];
//
NSKeyedUnarchiver *unArchiver = [[NSKeyedUnarchiver alloc]initForReadingWithData: data];
// ,
NSMutableDictionary *mudict = [NSMutableDictionary dictionaryWithCapacity:10];
//
[mudict addEntriesFromDictionary: [unArchiver decodeObjectForKey: @"QQ"]]; //
// , : +
NSMutableData *mudata = [[NSMutableData alloc]init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData: mudata];
// , , +
[mudict addEntriesFromDictionary:@{_QQRegNumber.text:_QQRegPassword.text} ];
// ( + )
[archiver encodeObject: mudict forKey:@"QQ"];
// : finishEncoding,
[archiver finishEncoding];
//
[mudata writeToFile:PATH atomically:YES];
//
_ResultMessage.text = @" !";
// NSLog( @"%@", [unArchiver decodeObjectForKey: @"QQ"] );
}
}
@end
.
View Controller, Button show, Button show
6. 페이지 전환 설정
오른쪽 Custon Class 에서 Class 의 ViewController 를 선택 하 십시오.
또는 새로 만 들 기, iOS - > Source - > Cocoa Touch Class 선택 UIViewController