项目功能

1. 记录自己创建的事件

(1) 可以保存在系统文件夹

(2) 也可以保存在自定义的文件夹

2. 创建自定义文件夹

实现方法

sqlite

1. 记事本表

(1) WID , title , note , time , FID

(2)    创建表

(3)    插入数据

(4) 删除数据

(5) 根据FID查询数据

(6)    更改数据

2. 文件夹表

(1) FID ,  title , time

(2) 创建表

(3) 插入数据

(4) 查询数据(All)

(5) 删除数据

代码实现

--- AppDelegate.m

1 #import "AppDelegate.h"

2 #import "MainListViewController.h"

3 #import "DataBaseHandle.h"

4

5 @interface AppDelegate ()6

7 @end8

9 @implementation AppDelegate10

11

12 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {13

14 self.window =[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];15

16

17 self.window.backgroundColor =[UIColor whiteColor];18

19 [self.window makeKeyAndVisible];20

21 //创建表

22 DataBaseHandle *dataBase =[DataBaseHandle shareDataBaseHandle];23 [dataBase openDB];24

25 [dataBase creatWordNoteTable];26

27 [dataBase creatFileMessageTable];28

29 [dataBase closeDB];30

31

32 MainListViewController *mainListVC =[[MainListViewController alloc] init];33

34

35 UINavigationController *mainListNaviVC =[[UINavigationController alloc] initWithRootViewController:mainListVC];36

37 self.window.rootViewController =mainListNaviVC;38

39 returnYES;40 }

---DataBaseHandle.h

#import #import"WordNote.h"#import"FileMessage.h"@interface DataBaseHandle : NSObject//数据库单例

+ (DataBaseHandle *)shareDataBaseHandle;//打开数据库

- (void)openDB;//关闭数据库

- (void)closeDB;//创建记事本表

- (void)creatWordNoteTable;//创建文件夹表

- (void)creatFileMessageTable;//向WoedNote表里边插入一个WoedNote类型的model

- (void)insertIntoWordNoteWith:(WordNote *)model;//向FileMessage表里边插入一个FileMessage类型的model

- (void)insertIntoFileMessageWith:(FileMessage *)model;//根据WID删除掉WordNote里边的某条数据

- (void)deleteFromWordNoteWithWID:(NSInteger)WID;//根据FID删除WordNote里边的一堆数据

- (void)deleteFromWordNoteWithFID:(NSInteger)FID;//根据FID删除FileMessage里边的一条数据

- (void)deleteFromFileMessageWithFID:(NSInteger)FID;//根据FID在WordNote表里边查询数据

- (NSMutableArray *)searchFromWordNoteWithFID:(NSInteger)FID;//查询FileMessage表里面所有的数据

- (NSMutableArray *)searchAllFromFileMessage;

---DataBaseHandle.m

1 #import "DataBaseHandle.h"

2 #import

3

4 @interface DataBaseHandle ()5

6 @property (nonatomic, strong) NSString *dbPath;7

8 @end9

10 static DataBaseHandle *dataBase =nil;11

12 @implementation DataBaseHandle13

14 + (DataBaseHandle *)shareDataBaseHandle15 {16 if (dataBase ==nil ) {17 dataBase = [DataBaseHandle new];18 }19 returndataBase;20 }21

22 - (NSString *)dbPath23 {24 if (!_dbPath) {25 NSString *document = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];26 _dbPath = [document stringByAppendingPathComponent:@"wordnote.sqlite"];27 }28 return_dbPath;29 }30

31 static sqlite3 *db =nil;32

33 - (void)openDB34 {35 int result = sqlite3_open(self.dbPath.UTF8String, &db);36

37 if (result ==SQLITE_OK) {38 NSLog(@"打开成功");39 }else{40 NSLog(@"失败了");41 }42

43 }44

45 - (void)closeDB46 {47 int result =sqlite3_close(db);48 if (result ==SQLITE_OK) {49 NSLog(@"关闭成功");50 }else{51 NSLog(@"关不上");52 }53

54 }55

56 - (void)creatWordNoteTable57 {58 NSString *creatString = @"create table if not exists WordNote (WID integer primary key autoincrement,title text, note text, time text, FID integer)";59 int result =sqlite3_exec(db, creatString.UTF8String, NULL, NULL, NULL);60

61 if (result ==SQLITE_OK) {62 NSLog(@"创表成功");63 }else

64 {65 NSLog(@"创表失败");66 }67 }68

69 - (void)creatFileMessageTable70 {71 NSString *creatString = @"create table if not exists FileMessage (FID integer primary key autoincrement ,title text, time text)";72

73 int result =sqlite3_exec(db, creatString.UTF8String, NULL, NULL, NULL);74

75 if (result ==SQLITE_OK) {76 NSLog(@"创建成功");77 }else

78 {79 NSLog(@"创你妹");80 }81 }82

83 - (void)insertIntoWordNoteWith:(WordNote *)model84 {85 //插入流程86 //第一步:创建一个SQL语句 insert into 表名 (字段) values (多少个字段要有多少个?)

87 NSString *insertString = @"insert into WordNote (title, note, time, FID) values (?, ?, ?, ?)";88 //第二步 : 创建一个伴随指针

89 sqlite3_stmt *stmt =nil;90 //第三步 : 使用sqlite3_prepare方法预执行SQL语句

91 int result = sqlite3_prepare(db, insertString.UTF8String, -1, &stmt, NULL);92 //第四步 : 判断是否预执行成功,如果成功了 进行下一步

93 if (result ==SQLITE_OK) {94 //第五步 : 向?的位置 插入数据

95 sqlite3_bind_text(stmt, 1, model.title.UTF8String, -1, NULL);96 sqlite3_bind_text(stmt, 2, model.note.UTF8String, -1, NULL);97 sqlite3_bind_text(stmt, 3, model.time.UTF8String, -1, NULL);98 sqlite3_bind_int64(stmt, 4, model.FID);99 //第六步 : 判断伴随指针是否完成

100 if (sqlite3_step(stmt) ==SQLITE_DONE) {101 NSLog(@"插入成功");102 }103 }else

104 {105

106 NSLog(@"错误信息 result== %d",result);107

108 }109

110 //第七步: 释放伴随指针

111 sqlite3_finalize(stmt);112 }113

114 - (void)insertIntoFileMessageWith:(FileMessage *)model115 {116 NSString *insertString = @"insert into FoleMessage (title, time) values (?, ?)";117

118 sqlite3_stmt *stmt =nil;119

120 int result = sqlite3_prepare(db, insertString.UTF8String, -1, &stmt, NULL);121

122 if (result ==SQLITE_OK) {123 sqlite3_bind_text(stmt, 1, model.title.UTF8String, -1, NULL);124 sqlite3_bind_text(stmt, 2, model.time.UTF8String, -1, NULL);125 if (sqlite3_step(stmt) ==SQLITE_DONE) {126 NSLog(@"插入成功");127 }128 }129 sqlite3_finalize(stmt);130 }131

132 #pragma mark -- 删除方法

133

134 - (void)deleteFromWordNoteWithWID:(NSInteger)WID135 {136 NSString *deleteString = [NSString stringWithFormat:@"delete from WordNote where WID = %ld", WID];137

138 int result =sqlite3_exec(db, deleteString.UTF8String, NULL, NULL, NULL);139 if (result ==SQLITE_OK) {140 NSLog(@"删除成功");141 }else{142 NSLog(@"删除失败");143 }144

145 }146

147 - (void)deleteFromWordNoteWithFID:(NSInteger)FID148 {149 NSString *deleteString = [NSString stringWithFormat:@"delete from WordNote where FID = %ld", FID];150

151 int result =sqlite3_exec(db, deleteString.UTF8String, NULL, NULL, NULL);152 if (result ==SQLITE_OK) {153 NSLog(@"删除成功");154 }else{155 NSLog(@"删除失败");156 }157 }158

159 - (void)deleteFromFileMessageWithFID:(NSInteger)FID160 {161 NSString *deleteString = [NSString stringWithFormat:@"delete from FileMessage where FID = %ld", FID];162

163 int result =sqlite3_exec(db, deleteString.UTF8String, NULL, NULL, NULL);164 if (result ==SQLITE_OK) {165 NSLog(@"删除成功");166 }else{167 NSLog(@"删除失败");168 }169 }170

171 - (NSMutableArray *)searchFromWordNoteWithFID:(NSInteger)FID172 {173 //查询步骤174 //第一步: 创建SQL语句

175 NSString *searchString = @"select * from WordNote where FID = ?";176 //第二步: 创建伴随指针

177 sqlite3_stmt *stmt =nil;178 //第三步: 让查询语句 预执行

179 int result = sqlite3_prepare(db, searchString.UTF8String, -1, &stmt, NULL);180

181 NSMutableArray *resultArray =[NSMutableArray array];182

183 //第四步: 判断预执行结果

184 if (result ==SQLITE_OK) {185 //第五步: 如果查询语句里面有 ? 需要一步绑定的过程

186 sqlite3_bind_int64(stmt, 1, FID);187 //第六步: 循环取值

188 while (sqlite3_step(stmt) ==SQLITE_ROW) {189 WordNote *model = [WordNote new];190

191 model.WID = sqlite3_column_int(stmt, 0);192 model.title = [NSString stringWithUTF8String:(const char *) sqlite3_column_text(stmt, 1)];193 model.note = [NSString stringWithUTF8String:(const char *) sqlite3_column_text(stmt, 2)];194 model.time = [NSString stringWithUTF8String:(const char *) sqlite3_column_text(stmt, 3)];195 model.FID = sqlite3_column_int(stmt, 4);196 [resultArray addObject:model];197 }198 }199 sqlite3_finalize(stmt);200 returnresultArray;201 }202

203 - (NSMutableArray *)searchAllFromFileMessage204 {205 NSString *searchString = @"select * from FileMessage";206

207 sqlite3_stmt *stmt =nil;208

209 int result = sqlite3_prepare(db, searchString.UTF8String, -1, &stmt, NULL);210

211 NSMutableArray *searchArray =[NSMutableArray array];212

213 if (result ==SQLITE_OK) {214 while (sqlite3_step(stmt) ==SQLITE_ROW) {215 FileMessage *model = [FileMessage new];216

217 model.title = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(stmt, 1)];218 model.time = [NSString stringWithUTF8String:(const char *)sqlite3_column_text(stmt, 2)];219 model.FID = sqlite3_column_int(stmt, 3);220 [searchArray addObject:model];221 }222 }223 sqlite3_finalize(stmt);224 returnsearchArray;225 }226

227 @end

----MainListViewController.m

#import "MainListViewController.h"#import"MainListOneLabelCollectionViewCell.h"#import"MainListTimeLabelCollectionViewCell.h"#import"MainListCollectionReusableView.h"#import"NoteViewController.h"#import"AddFileViewController.h"#import"DataBaseHandle.h"#import"MyLongPressGestureRecognizer.h"@interface MainListViewController ()@property (nonatomic, strong) UICollectionView*collectionView;

@end

@implementation MainListViewController- (void)viewDidLoad {

[super viewDidLoad];

}- (void)loadData

{

[super loadData];

DataBaseHandle*dataBaseHandle =[DataBaseHandle sharedDataBaseHandle];

[dataBaseHandle openDB];

self.dataArray=[dataBaseHandle searchAllFromFileMessage];

[self.collectionView reloadData];

}- (void)createView

{

[super createView];

UICollectionViewFlowLayout*flowLayout =[[UICollectionViewFlowLayout alloc] init];

flowLayout.itemSize= CGSizeMake(90, 90);

flowLayout.headerReferenceSize= CGSizeMake(self.view.frame.size.width, 20);

flowLayout.minimumInteritemSpacing= 10;

flowLayout.minimumLineSpacing= 10;

flowLayout.sectionInset= UIEdgeInsetsMake(10, 10, 10, 10);

self.collectionView=[[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:flowLayout];

self.collectionView.backgroundColor=[UIColor whiteColor];

self.collectionView.delegate =self;

self.collectionView.dataSource=self;

[self.view addSubview:self.collectionView];

[self.collectionView registerClass:[MainListOneLabelCollectionViewCellclass] forCellWithReuseIdentifier:@"oneLabelCELL"];

[self.collectionView registerClass:[MainListOneLabelCollectionViewCellclass] forCellWithReuseIdentifier:@"addCELL"];

[self.collectionView registerClass:[MainListTimeLabelCollectionViewCellclass] forCellWithReuseIdentifier:@"timeLabelCELL"];

[self.collectionView registerClass:[MainListCollectionReusableViewclass] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView"];

}- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

{return 2;

}- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

{switch(section) {case 0:return 1;break;case 1:return self.dataArray.count + 1;break;default:return 1000;break;

}

}- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

{switch(indexPath.section) {case 0:{

MainListOneLabelCollectionViewCell*cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"oneLabelCELL"forIndexPath:indexPath];returncell;

}break;case 1:{switch(indexPath.row) {case 0:{

MainListOneLabelCollectionViewCell*cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"addCELL"forIndexPath:indexPath];

cell.titleLabel.text= @"+";

cell.titleLabel.font= [UIFont systemFontOfSize:50];returncell;

}break;default:{

MainListTimeLabelCollectionViewCell*cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"timeLabelCELL"forIndexPath:indexPath];

FileMessage*message = self.dataArray[indexPath.row - 1];

[cell bindModel:message];//给cell添加一个长按手势

MyLongPressGestureRecognizer *longPG =[[MyLongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPGAction:)];

longPG.indexPath=indexPath;

[cell addGestureRecognizer:longPG];returncell;

}break;

}

}break;default:{

UICollectionViewCell*cell =nil;returncell;

}break;

}

}- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

{

MainListCollectionReusableView*reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"headerView"forIndexPath:indexPath];switch(indexPath.section) {case 0:

reusableView.titleLabel.text= @"系统文件夹";break;case 1:

reusableView.titleLabel.text= @"我的文件夹";break;default:break;

}returnreusableView;

}- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

{switch(indexPath.section) {case 0:{

NoteViewController*noteVC =[[NoteViewController alloc] init];

[self.navigationController pushViewController:noteVC animated:YES];

}break;case 1:{switch(indexPath.row) {case 0:{

AddFileViewController*addFileVC =[[AddFileViewController alloc] init];typeof(self) pSelf =self;

addFileVC.MyBlock= ^(){

[pSelf loadData];

};

[self.navigationController pushViewController:addFileVC animated:YES];

}break;default:{

NoteViewController*noteVC =[[NoteViewController alloc] init];

FileMessage*message = self.dataArray[indexPath.row - 1];

noteVC.FID=message.FID;

[self.navigationController pushViewController:noteVC animated:YES];

}break;

}

}default:break;

}

}//长按收拾的触发方法

- (void)longPGAction:(MyLongPressGestureRecognizer *)longPG

{

UIAlertController*controller = [UIAlertController alertControllerWithTitle:@"是否删除这个文件夹"message:nil preferredStyle:UIAlertControllerStyleAlert];typeof(self) pSelf =self;

UIAlertAction*action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {

DataBaseHandle*dataBase =[DataBaseHandle sharedDataBaseHandle];

[dataBase openDB];

FileMessage*fileMessage = pSelf.dataArray[longPG.indexPath.row - 1];

[dataBase deleteFromFileMessageWithFID:fileMessage.FID];

[dataBase deleteFromWordNoteWithFID:fileMessage.FID];

[pSelf loadData];

}];

UIAlertAction*action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *_Nonnull action) {

}];

[controller addAction:action];

[controller addAction:action1];

[self presentViewController:controller animated:YES completion:nil];

}- (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.

}*/@end

-----MainListOneLabelCollectionViewCell.h

#import @interface MainListOneLabelCollectionViewCell : UICollectionViewCell

@property (nonatomic, strong) UILabel*titleLabel;

@end

----MainListOneLabelCollectionViewCell.m

#import "MainListOneLabelCollectionViewCell.h"

@interface MainListOneLabelCollectionViewCell()

@end

@implementation MainListOneLabelCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame

{

self = [super initWithFrame:frame];

if (self) {

self.titleLabel = [[UILabel alloc] init];

self.titleLabel.text = @"系统文件夹";

self.titleLabel.textAlignment = NSTextAlignmentCenter;

[self.contentView addSubview:self.titleLabel];

self.backgroundColor = [UIColor greenColor];

self.layer.cornerRadius = 10;

self.layer.borderWidth = 0.5;

self.layer.borderColor = [UIColor darkGrayColor].CGColor;

}

return self;

}

- (void)layoutSubviews

{

[super layoutSubviews];

self.titleLabel.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);

}

@end

-----MainListTimeLabelCollectionViewCell.h

#import #import"FileMessage.h"@interface MainListTimeLabelCollectionViewCell : UICollectionViewCell- (void)bindModel:(FileMessage *)model;

@end

-----MainListTimeLabelCollectionViewCell.m

#import "MainListTimeLabelCollectionViewCell.h"@interface MainListTimeLabelCollectionViewCell()

@property (nonatomic, strong) UILabel*titleLabel;

@property (nonatomic, strong) UILabel*timeLabel;

@end

@implementation MainListTimeLabelCollectionViewCell-(instancetype)initWithFrame:(CGRect)frame

{

self=[super initWithFrame:frame];if(self) {

self.titleLabel=[[UILabel alloc] init];

[self.contentView addSubview:self.titleLabel];

self.titleLabel.text= @"我的文件夹";

self.backgroundColor=[UIColor greenColor];

self.titleLabel.textAlignment=NSTextAlignmentCenter;

self.timeLabel=[[UILabel alloc] init];

[self.contentView addSubview:self.timeLabel];

self.timeLabel.font= [UIFont systemFontOfSize:10];

self.timeLabel.text= @"2016-03-28";

self.timeLabel.textAlignment=NSTextAlignmentCenter;

self.layer.cornerRadius= 10;

self.layer.borderWidth= 0.5;

self.layer.borderColor=[UIColor darkGrayColor].CGColor;

}returnself;

}- (void)layoutSubviews

{

[super layoutSubviews];

self.titleLabel.frame= CGRectMake(0, 0, self.frame.size.width, self.frame.size.height / 2);

self.timeLabel.frame= CGRectMake(0, self.frame.size.height / 2, self.frame.size.width, self.frame.size.height / 2);

}

@end

--------MainListCollectionReusableView.h

#import @interface MainListCollectionReusableView : UICollectionReusableView

@property (nonatomic, strong) UILabel*titleLabel;

@end

--------MainListCollectionReusableView.m

#import "MainListCollectionReusableView.h"@implementation MainListCollectionReusableView-(instancetype)initWithFrame:(CGRect)frame

{

self=[super initWithFrame:frame];if(self) {

self.titleLabel=[[UILabel alloc] init];

self.titleLabel.textAlignment=NSTextAlignmentLeft;

self.titleLabel.backgroundColor= [[UIColor blackColor] colorWithAlphaComponent:0.5];

[self addSubview:self.titleLabel];

}returnself;

}- (void)layoutSubviews

{

[super layoutSubviews];

self.titleLabel.frame= CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);

}

@end

---------NoteViewController.h

#import "BaseViewController.h"@interface NoteViewController : BaseViewController

@property (nonatomic, assign) NSInteger FID;

@end

---------NoteViewController.m

#import "NoteViewController.h"#import"NoteListTableViewCell.h"#import"AddNoteViewController.h"#import"DataBaseHandle.h"#import"WordNote.h"@interface NoteViewController ()@property (nonatomic, strong) UITableView*tableView;

@end

@implementation NoteViewController- (void)viewDidLoad

{

[super viewDidLoad];

}- (void)loadData

{

[super loadData];

DataBaseHandle*dataBaseHandle =[DataBaseHandle shareDataBaseHandle];

[dataBaseHandle openDB];

self.dataArray=[dataBaseHandle searchFromWordNoteWithFID:self.FID];

[self.tableView reloadData];

}- (void)createView{

[super createView];

self.tableView=[[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];

self.tableView.delegate =self;

self.tableView.dataSource=self;

[self.view addSubview:self.tableView];

[self.tableView registerClass:[NoteListTableViewCellclass] forCellReuseIdentifier:@"CELL"];

UIBarButtonItem*barButtonItem =[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(barButtonItemClicked)];

self.navigationItem.rightBarButtonItem=barButtonItem;

}- (void)barButtonItemClicked

{

AddNoteViewController*addNoteVC =[[AddNoteViewController alloc] init];

[self.navigationController pushViewController:addNoteVC animated:YES];

}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{returnself.dataArray.count;

}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

NoteListTableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:@"CELL"forIndexPath:indexPath];

WordNote*model =self.dataArray[indexPath.row];

[cell bindModel:model];returncell;

}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

AddNoteViewController*addNoteVC =[[AddNoteViewController alloc] init];

addNoteVC.FID = self.FID;

addNoteVC.view.backgroundColor = [UIColor brownColor];

WordNote *model = self.dataArray[indexPath.row];

[addNoteVC bindModel:model];

[self.navigationController pushViewController:addNoteVC animated:YES];

}

@end

-----NoteListTableViewCell.h

#import #import"WordNote.h"@interface NoteListTableViewCell : UITableViewCell- (void)bindModel:(WordNote *)model;

@end

-----NoteListTableViewCell.m

#import "NoteListTableViewCell.h"@interface NoteListTableViewCell ()

@property (nonatomic, strong) UILabel*titleLabel;

@property (nonatomic, strong) UILabel*timeLabel;

@end

@implementation NoteListTableViewCell-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];if(self) {

self.titleLabel=[[UILabel alloc] init];

[self.contentView addSubview:self.titleLabel];

self.titleLabel.text= @"今天的事情";

self.titleLabel.textAlignment=NSTextAlignmentLeft;

self.timeLabel=[[UILabel alloc] init];

self.timeLabel.text= @"2016-03-28";

[self.contentView addSubview:self.timeLabel];

}returnself;

}- (void)bindModel:(WordNote *)model

{

self.titleLabel.text=model.title;

self.timeLabel.text=model.time;

}- (void)layoutSubviews

{

[super layoutSubviews];

self.titleLabel.frame= CGRectMake(0, 0, self.frame.size.width / 3 * 2, self.frame.size.height);

self.timeLabel.frame= CGRectMake(self.frame.size.width / 3 * 2, 0, self.frame.size.width / 3, self.frame.size.height);

}- (void)awakeFromNib {//Initialization code

}- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

[super setSelected:selected animated:animated];//Configure the view for the selected state

}

@end

-------AddNoteViewController.h

#import "BaseViewController.h"

#import "WordNote.h"

typedef void(^block)();

@interface AddNoteViewController : BaseViewController

@property (nonatomic, copy) block myBlock;

@property (nonatomic, assign) NSInteger FID;

- (void)bindModel:(WordNote *)model;

@end

-------AddNoteViewController.m

#import "AddNoteViewController.h"

#import "DataBaseHandle.h"

@interface AddNoteViewController ()

@property (nonatomic, strong)UITextField *titleTextField;

@property (nonatomic, strong) UITextView *textView;

@end

@implementation AddNoteViewController

- (void)viewDidLoad {

[super viewDidLoad];

}

- (void)createView

{

self.view.backgroundColor = [UIColor brownColor];

self.titleTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 74, self.view.frame.size.width - 20, 30)];

self.titleTextField.backgroundColor = [UIColor whiteColor];

self.titleTextField.placeholder = @"请输入标题";

self.titleTextField.textAlignment = NSTextAlignmentCenter;

[self.view addSubview:self.titleTextField];

self.textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 114, self.view.frame.size.width - 20, self.view.frame.size.height - 124)];

[self.view addSubview:self.textView];

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(barButtonItemClicked)];

self.navigationItem.rightBarButtonItem = barButtonItem;

}

- (void)barButtonItemClicked

{

DataBaseHandle *dataBaseHandle = [DataBaseHandle sharedDataBaseHandle];

[dataBaseHandle openDB];

WordNote *wordNote = [[WordNote alloc] init];

wordNote.title = self.titleTextField.text;

wordNote.note = self.textView.text;

wordNote.FID = self.FID;

NSDate *date = [NSDate date];

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setDateFormat:@"YYYY-MM-dd"];

wordNote.time = [formatter stringFromDate:date];

[dataBaseHandle insertIntoWordNoteWith:wordNote];

[dataBaseHandle closeDB];

self.myBlock();

[self.navigationController popViewControllerAnimated:YES];

}

- (void)bindModel:(WordNote *)model

{

self.titleTextField.text = model.title;

self.textView.text = model.note;

// 不让用户编辑了,所以关闭用户交互

self.titleTextField.userInteractionEnabled = NO;

self.textView.userInteractionEnabled = NO;

// 不需要保存,所以右边的置为nil

self.navigationItem.rightBarButtonItem = nil;

}

- (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.

}

*/

@end

-------AddFileViewController.h

#import "BaseViewController.h"

//使用block回调 让上一个页面刷新

typedef void(^block)();

@interface AddFileViewController : BaseViewController

@property (nonatomic, copy) block MyBlock;

@end

-------AddFileViewController.m

#import "AddFileViewController.h"

#import "DataBaseHandle.h"

#import "FileMessage.h"

@interface AddFileViewController ()

@property (nonatomic, strong)UITextField *titleTextField;

@end

@implementation AddFileViewController

- (void)viewDidLoad {

[super viewDidLoad];

}

- (void)createView

{

self.view.backgroundColor = [UIColor blackColor];

self.titleTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 74, self.view.frame.size.width - 20, 30)];

self.titleTextField.textAlignment = NSTextAlignmentCenter;

self.titleTextField.backgroundColor = [UIColor whiteColor];

self.titleTextField.placeholder = @"请输入标题";

[self.view addSubview:self.titleTextField];

// 创建右边的barbuttonitem

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(barButtonItemClicked)];

self.navigationItem.rightBarButtonItem = barButtonItem;

}

- (void)barButtonItemClicked

{

// 存储数据

DataBaseHandle *dataBaseHandle = [DataBaseHandle sharedDataBaseHandle];

[dataBaseHandle openDB];

FileMessage *fileMessage = [[FileMessage alloc] init];

fileMessage.title = self.titleTextField.text;

NSDate *date = [NSDate date];

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

[formatter setDateFormat:@"YYYY-MM-dd"];

fileMessage.time = [formatter stringFromDate:date];

[dataBaseHandle insertIntoFileMessageWith:fileMessage];

// 触发自己的block

self.MyBlock();

[self.navigationController popViewControllerAnimated:YES];

}

- (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.

}

*/

@end

------WordNote.h

#import @interface WordNote : NSObject//记事本

@property(nonatomic, assign) NSInteger WID;//记事本Title

@property(nonatomic, strong) NSString *title;//记事本记录的内容

@property(nonatomic, strong) NSString *note;//记录的时间

@property(nonatomic, strong) NSString *time;//文件夹的ID

@property(nonatomic, assign) NSInteger FID;

@end

----FileMessage.h

#import @interface FileMessage : NSObject

@property (nonatomic, assign) NSInteger FID;

@property (nonatomic, copy) NSString*title;

@property (nonatomic, copy) NSString*time;

@end

mysql实现记事本_记事本 __ 数据库相关推荐

  1. mysql 多线程 一致性_常见缓存数据库一致性方案(建议收藏)

    项目中常常会用到redis 作为缓存抵挡大量流量直接冲击数据库mysql,那么必然涉及缓存和数据库数据的一致性(尽量短时间内最终一致性)问题. 导致不一致的原因主要有三种情况: 1:并发下,读取旧数据 ...

  2. 提高mysql查询速度_如何提高数据库查询速度

    1.用程序中, 保证在实现功能的基础上,尽量减少对数据库的访问次数: 通过搜索参数,尽量减少对表的访问行数,最小化结果集,从而减轻网络负担: 能够分开的操作尽量分开处理,提高每次的响应速度: 在数据窗 ...

  3. mysql 增量备份_云计算-开源数据库-备份

    关于备份: 备份原因:怕丢,怕被误删. 备份目标:数据的一致性,服务的可用性. 备份技术:物理备份/冷备份 直接复制数据库文件,适用于大型数据库环境,不受存储引擎的限制,但不能恢复到不同的MySQL版 ...

  4. es mysql 同步插件_[es和数据库怎么同步]mysql与elasticsearch实时同步常用插件及优缺点对比(ES与关系型数据库同步)...

    目前mysql与elasticsearch常用的同步机制大多是基于插件实现的,常用的插件包括:elasticsearch-jdbc,elasticsearch-river-MySQL,go-mysql ...

  5. Rds基于mysql开发的_开发云数据库RDS MYSQL版讲解

    前言 这篇文章适合所有的 C# 开发新手.老鸟以及想准备学习开发 C# 的程序猿..NET Core是一个开源通用的开发框架,支持跨平台, 阿里云函数计算推出了 dotnetcore2.1 runti ...

  6. oracle数据库跟mysql的区别_关于Oracle数据库与MySQL数据库的几点区别

    Oracle数据库与MySQL数据库的区别是本文我们主要要介绍的内容,接下来我们就开始介绍这部分内容,希望能够对您有所帮助. Oracle与MySQL的区别: 1.在Oracle中用select * ...

  7. 怎样用mysql查询测试_如何测试数据库查询优化器

    我一直认为,查询优化器(Query Optimizer,后面简称优化器)一直是数据库领域 Top 级别的 hardcore 技术,自己也一直尝试去深入理解,但每每看到 TiDB 代码里面那一大坨 pl ...

  8. django mysql数据同步_[django同步数据库]Django去操作已经存在数据的数据库

    数据库,各种表结构已经创建好了,甚至连数据都有了,此时,我要用Django管理这个数据库,ORM映射怎么办??? Django是最适合所谓的green-field开发,即从头开始一个新的项目 但是呢, ...

  9. ecshop mysql 报错_修复ecshop数据库ecs_sessions.MYI报错

    由于 MySQL 本身的读写及锁定机制等方面的原因,与一些其他数据库软件一样,在特殊情况下的极为频繁读写时,或在服务器掉电.死机等情况下,相关的数据文件可能会发生被损坏的情况,通常可以采用以下的方式加 ...

最新文章

  1. 强烈推荐:240多个jQuery插件
  2. Centos mysql的安装和配置
  3. postgresql 备份_在Kubernetes上使用PostgreSQL的正确姿势:第三部分
  4. python的for循环语句怎么写_python中的for循环语句怎么写
  5. SSH Secure File Transfer上传文件错误:encountered 1 errors during the transfer解决办法
  6. Yii2 的 redis 应用
  7. ios基础篇(二十六)—— UITableViewCell的分组索引与标记
  8. OpenCV学习笔记十:hough变换
  9. 如约而至 Nexus 6 的 Android 7.1.1 已经上线
  10. golang文件夹位置判断
  11. 微课|中学生可以这样学Python(例9.1):Excel导入SQLite(2)
  12. C++ vector和list的区别及使用场景
  13. java第七章jdbc课后简答题_jsp编程基础第七章习题
  14. 详解SQL2005中的AWE
  15. 转-PHP 设计模式 之策略模式 应用场景 Strategy Pattern
  16. 使用微PE制作启动U盘重装系统教程
  17. 节点精灵 控制循环时间
  18. linux命令之dnf命令
  19. AssertionError: Torch not compiled with CUDA enabled问题
  20. 全球PM25实时可视化

热门文章

  1. 【MAC使用技巧】Safari、qq浏览器等设置F5刷新快捷键
  2. 那些年,腾讯走过的运营路
  3. 顺利实施数字化战略的十大诀窍
  4. python list 转数组assay
  5. C++ | 匿名函数(lambda表达式)
  6. 四川大学计算机学院卢莉,四川大学卢莉等 | 用于视频跟踪的非对称判别相关滤波器...
  7. win10屏幕亮度调不了(Win10屏幕亮度)
  8. 编程小白的第一本Python入门书学习笔记 Chapter4: 函数
  9. 翻翻git之---实现下拉到底刷新RecycleView InfiniteScroll
  10. 华为:用一个圈子联接一个圈子