经过昨天下午和今天上午的不懈努力,终于通过了SQLite的学习。

我们现在这里定义一个有关SQLIte的封装类,便于我在后面的用户注册,用户密码找回,和登录界面的使用

1.首先我们看看我们建立的userModel,虽然很多属性没有使用,但是作为备用

LCUserMessageModel.h文件。

#import <Foundation/Foundation.h>

@interface LCUserMessageModel : NSObject<NSCoding>

@property (assign,nonatomic)NSInteger QQ;

@property (copy,nonatomic)NSString *userName;
@property (copy,nonatomic)NSString *userAddress;
@property (copy,nonatomic)NSString *userMobilephineNumber;
@property (copy,nonatomic)NSString *userPassword;
@property (copy,nonatomic)NSString *userRePassword;
@property (copy,nonatomic)NSString *userStuID;
@property (copy,nonatomic)NSString *userSeriousFriendName;
@property (copy,nonatomic)NSString *userPIDSixNumber; @end

LCUserMessageModel.m文件,要说明的是,如果我是用了SQLite进行存储,那么就不需要NSCODing协议了,但是我使用的原因是因为我多次修改,使用了文件存储的方法。

//
// LCUserMessageModel.m
// 手机QQ客户端
//
// Created by lichan on 13-12-11.
// Copyright (c) 2013年 com.lichan. All rights reserved.
// #import "LCUserMessageModel.h" @implementation LCUserMessageModel @synthesize QQ, userAddress,userMobilephineNumber,userName,userPassword,userPIDSixNumber,userRePassword,userSeriousFriendName,userStuID; - (void)encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeInteger:QQ forKey:@"QQ"];
[aCoder encodeObject:userName forKey:@"userName"];
[aCoder encodeObject:userAddress forKey:@"userAddress"];
[aCoder encodeObject:userMobilephineNumber forKey:@"userMobilephineNumber"];
[aCoder encodeObject:userPassword forKey:@"userPassword"];
[aCoder encodeObject:userRePassword forKey:@"userRePassword"];
[aCoder encodeObject:userStuID forKey:@"userStuID"];
[aCoder encodeObject:userSeriousFriendName forKey:@"userSeriousFriendName"];
[aCoder encodeObject:userPIDSixNumber forKey:@"userPIDSixNumber"]; } - (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super init]) {
self.QQ = [aDecoder decodeIntegerForKey:@"QQ"];
self.userName = [aDecoder decodeObjectForKey:@"userName"];
self.userAddress = [aDecoder decodeObjectForKey:@"userAddress"];
self.userMobilephineNumber = [aDecoder decodeObjectForKey:@"userMobilephineNumber"];
self.userPassword = [aDecoder decodeObjectForKey:@"userPassword"];
self.userRePassword = [aDecoder decodeObjectForKey:@"userRePassword"];
self.userStuID = [aDecoder decodeObjectForKey:@"userStuID"];
self.userSeriousFriendName = [aDecoder decodeObjectForKey:@"userSeriousFriendName"];
self.userPIDSixNumber = [aDecoder decodeObjectForKey:@"userPIDSixNumber"];
} return self; } -(NSString *)description
{
return [NSString stringWithFormat:@"QQ:%d password:%@",self.QQ,self.userPassword];
} @end

2.关于SQLite进行属性封装的类。很明显,我继承了NSOBject类型。注释给予说明

#import <Foundation/Foundation.h>
#import <sqlite3.h>
@class LCUserMessageModel;
@interface LCSQLite3Methods : NSObject
{
sqlite3 *database;
NSError *error;
NSString *DBFilePath;
} - (LCUserMessageModel *)queryFromDB; //查找所有的QQ注册信息,很多时候用不上 - (NSInteger)insertORUpdateToDB:(LCUserMessageModel *)user;//注册账号的使用调用 - (NSMutableArray *)findUserPasswordByMobilePhoneNumber:(NSString *)phoneNumber;//找回密码界面调用此方法 - (NSMutableArray *)findUserPasswordByQQ:(NSInteger )qq Password:(NSString *)password;//用户登录时候调用此方法
@end

3.密码找回界面,SQLite接口类的使用

1)LCFInd.h文件,不再赘述

#import <UIKit/UIKit.h>
@class LCSQLite3Methods; @interface LCFindPSWViewController : UIViewController @property (weak, nonatomic) IBOutlet UITextField *mobilePhoneNumber; @property (strong,nonatomic)LCSQLite3Methods *SQLiteMethods; - (IBAction)findPSWButtonPressed:(id)sender; -(IBAction)textFieldDoneEditing:(id)sender; @end

2)实现文件,由于我只能依赖手机号进行找回,除非用户写入了QQ。唯一保险的办法是直接找回所有通过此手机号注册的所有QQ和密码。后续会完善此BUG。

#import "LCFindPSWViewController.h"
#import "LCSQLite3Methods.h"
#import "LCUserMessageModel.h" @interface LCFindPSWViewController ()
@property (strong,nonatomic)LCUserMessageModel *userModel;
@end @implementation LCFindPSWViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) { self.title = @"密码找回"; // Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBarHidden = NO;
self.SQLiteMethods = [[LCSQLite3Methods alloc]init];
// Do any additional setup after loading the view from its nib.
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (IBAction)findPSWButtonPressed:(id)sender { NSString *MPnumber = self.mobilePhoneNumber.text; NSMutableArray *findArray =[self.SQLiteMethods findUserPasswordByMobilePhoneNumber:MPnumber]; NSString *message = [NSString stringWithFormat:@"此手机号注册的QQ号码:%@",findArray];
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"恭喜您,密码找回成功!" message:message delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil]; [alertView show]; // self.userModel = [[LCUserMessageModel alloc]init];
//
// NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSAllDomainsMask, YES) objectAtIndex:0];
// NSString *userFilePath = [path stringByAppendingPathComponent:self.mobilePhoneNumber.text];
//
// NSMutableData *data = [NSMutableData dataWithContentsOfFile:userFilePath];
//
// self.userModel = [NSKeyedUnarchiver unarchiveObjectWithData:data];
//
// NSString *MPnumber = self.mobilePhoneNumber.text;
//
// NSString *message = [NSString stringWithFormat:@"已初始化账号为%@的密码为%@,请尽快修改密码。",MPnumber,self.userModel.userPassword];
// UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"恭喜您,密码找回成功!" message:message delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil];
//
// [alertView show];
} #pragma mark 取消键盘响应的方法
-(IBAction)textFieldDoneEditing:(id)sender
{
[sender resignFirstResponder]; } @end

[课堂实践与项目]手机QQ客户端--4期(SQLite的加入,注册,找回,登录界面的修改):建立关于QQ注册类,使用SQLite进行存储,的更多相关文章

  1. [课堂实践与项目]NavigationController与TabBarController的综合使用及易错点分析(包含消息提醒,app更新)

    陈述:我们在使用tabbarController的时候,我们总会和NavagationController联合起来.但是不联合的时候又是什么样的一种pool的情况呢?我们就单单的 TabBarCont ...

  2. [课堂实践与项目]IOS优先级的计算器

    这个计算器主要是使用数组进行实现的.虽然没有使用前缀后缀表达式,但是是一种方法o. .h文件 // // LCViewController.h // 具有优先级的calculator // // Cr ...

  3. [课堂实践与项目]IOS只能进行简单的加减乘除的没有优先级的计算器

    // // LCViewController.m // calculator // // Created by lichan on 13-12-3. // Copyright (c) 2013年 co ...

  4. app分享时判断手机是否已安装微信或QQ客户端

    /** * 判断 用户是否安装微信客户端 */ public static boolean isWeixinAvilible(Context context) { final PackageManag ...

  5. 2016-2017-2 《Java 程序设计》课堂实践项目

    目录 基本工具 基础内容 Hello World 和 模块分解 数组的使用 命令行参数 递归 分支语句 String类的使用 类的定义与测试 多态 IO与异常 数据库 网络与安全 数据结构应用 And ...

  6. 《Java 程序设计》课堂实践项目 课后学习总结

    <Java 程序设计>课堂实践项目 课后学习总结 String类的使用(sort) 目录 Linux命令(sort) 课堂实践 课后思考 学习老师的代码之后的思考:int与Integer ...

  7. 《Java 程序设计》课堂实践项目汇总链接

    1.<Java 程序设计>课堂实践项目-命令行参数 2.<Java 程序设计>课堂实践项目-mini dc 3.<Java 程序设计>课堂实践项目-Arrays和S ...

  8. 《Java 程序设计》课堂实践项目-类定义

    <Java 程序设计>课堂实践项目类定义 课后学习总结 目录 改变 类定义实验要求 课堂实践成果 课后思考 改变 修改了博客整体布局,过去就贴个代码贴个图很草率,这次布局和内容都有修改. ...

  9. 《Java 程序设计》课堂实践项目-简易计算器

    <Java 程序设计>课堂实践项目简易计算器 课后学习总结 目录 改变 简易计算器实验要求 课堂实践成果 课后思考 改变 修改了博客整体布局,过去就贴个代码贴个图很草率,这次布局和内容都有 ...

随机推荐

  1. Laravel 5.1 事件、事件监听的简单应用

    ​ 有时候当我们单纯的看 Laravel 手册的时候会有一些疑惑,比如说系统服务下的授权和事件,这些功能服务的应用场景是什么,其实如果没有经历过一定的开发经验有这些疑惑是很正常的事情,但是当我们在工作 ...

  2. Couldn't get lock for %t/vertx.log

    今天在启动vertx框架的项目时,报“Couldn't get lock for %t/vertx.log”的错误. 解决方案: 1,找出vertx.log的目录.一般在(C:\Users\Admin ...

  3. Oracle课堂实验一“表的使用”代码。

    --创建本地管理表空间CustomerTBSCREATE TABLESPACE CustomerTBS         DATAFILE 'd:\Oracle11\product\11.2.0\ora ...

  4. ubuntu apt-get

    近期重新拿起linux的书看了下,整理了一下linux的命令. ubuntu预装了APT和dpkg ,“APT”是 “Advanced Package Tool”的简写,“dpkg ”是“Debian ...

  5. tpl demo

    using System; using System.Collections.Concurrent; using System.Threading; using System.Threading.Ta ...

  6. CCTV评论员评论步行者与奇才的比赛

    步行者客场迎战主场作战的奇才,奇才的战士可能由于过度兴奋或是过度紧张身体僵硬,本来能打进的球都失掉了.反而,由于步行者取得了两位数的领先,越大心情越放松,打出了过去很少见的流畅局面. CCTV评论员就 ...

  7. why app_start start

    Add following code for your class: [assembly: WebActivatorEx.PostApplicationStartMethod(typeof(WeCha ...

  8. js获取域名的方法

    本文实例讲述了js获取域名的方法.分享给大家供大家参考.具体实现方法如下: 复制代码代码如下: <script>//获取域名var k_host = window.location.hos ...

  9. 【网络流24题】No.19 负载平衡问题 (费用流)

    [题意] G 公司有 n 个沿铁路运输线环形排列的仓库, 每个仓库存储的货物数量不等. 如何用最少搬运量可以使 n 个仓库的库存数量相同.搬运货物时,只能在相邻的仓库之间搬运. 输入文件示例input ...

  10. Android Canvas使用drawBitmap绘制图片

    1.基本的绘制图片方法 //Bitmap:图片对象,left:偏移左边的位置,top: 偏移顶部的位置 drawBitmap(Bitmap bitmap, float left, float top, ...