Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 21451198卢超/project4/Note/AddNoteViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// AddNoteViewController.h
// Note
//
// Created by jiaoshoujie on 14-11-21.
// Copyright (c) 2014年 ___FULLUSERNAME___. All rights reserved.
//

#import "ViewController.h"

@interface AddNoteViewController : ViewController
@property (weak, nonatomic) IBOutlet UITextView *textView;

@property (nonatomic,strong) NSString *databaseFilePath;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *rightButon;

@end
133 changes: 133 additions & 0 deletions 21451198卢超/project4/Note/AddNoteViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//
// AddNoteViewController.m
// Note
//
// Created by jiaoshoujie on 14-11-21.
// Copyright (c) 2014年 ___FULLUSERNAME___. All rights reserved.
//

#import "AddNoteViewController.h"
#import "sqlite3.h"
#define kDatabaseName @"database.sqlite3"

@interface AddNoteViewController ()

@end

@implementation AddNoteViewController

@synthesize databaseFilePath;
@synthesize rightButon;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//获取数据库文件路径
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
self.databaseFilePath = [documentsDirectory stringByAppendingPathComponent:kDatabaseName];
}

//关闭键盘
- (IBAction)backgroundTap:(id)sender {
[_textView resignFirstResponder];
}

-(void)viewDidAppear:(BOOL)animated{

}

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

- (IBAction)addNoteAction:(id)sender {
//UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了导航栏右按钮" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//[alter show];
NSString *title = [[NSString alloc] initWithCString:"完成" encoding:NSUTF8StringEncoding];
NSLog(@"title:%@,rightButton:%@",title,rightButon.title);
NSLog(@"textView:%@",_textView.text);
if ([title isEqualToString:rightButon.title]&&![[[NSString alloc]initWithCString:"" encoding:NSUTF8StringEncoding]isEqualToString:_textView.text] ) {
[self insertIntoDatabase];
[rightButon setTitle:@"添加"];
_textView.text = nil;
}else{
[rightButon setTitle:@"完成"];
}
}

-(void)insertIntoDatabase{
//打开数据库
sqlite3 *database;
if (sqlite3_open([self.databaseFilePath UTF8String], &database)!=SQLITE_OK) {
sqlite3_close(database);
NSAssert(0, @"打开数据库失败!");
}
int last = [self lastTagofNotes];
//使用约束变量插入数据
char *update = "INSERT OR REPLACE INTO NOTES (TAG, DETAILS, THEDATETIME) VALUES (?,?,?);";
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(database, update, -1, &stmt, nil) == SQLITE_OK) {
sqlite3_bind_int(stmt, 1, last+1);
sqlite3_bind_text(stmt, 2, [_textView.text UTF8String], -1, NULL);
NSDate* date = [NSDate date];
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:MM:SS"];
NSString* str = [formatter stringFromDate:date];
NSLog(@"现在时间是:%@",str);
sqlite3_bind_text(stmt, 3, [str UTF8String], -1, NULL);
}
char *errorMsg = NULL;
if (sqlite3_step(stmt) != SQLITE_DONE) {
NSAssert(0, @"更新数据库表FIELDS出错:%s",errorMsg);
}
sqlite3_finalize(stmt);
//关闭数据库
sqlite3_close(database);
}

-(int)lastTagofNotes{
//打开数据库
sqlite3 *database;
if (sqlite3_open([self.databaseFilePath UTF8String], &database)!=SQLITE_OK) {
sqlite3_close(database);
NSAssert(0, @"打开数据库失败!");
}
int lastTag = 0;
char *update = "SELECT MAX(TAG) FROM NOTES";
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(database, update, -1, &stmt, nil) == SQLITE_OK){
while (sqlite3_step(stmt)==SQLITE_ROW){
lastTag = sqlite3_column_int(stmt, 0);
}
sqlite3_finalize(stmt);
}
sqlite3_close(database);

return lastTag;
}

/*
#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
14 changes: 14 additions & 0 deletions 21451198卢超/project4/Note/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// AppDelegate.h
// Note
//
// Created by jiaoshoujie on 14-11-21.
// Copyright (c) 2014年 ___FULLUSERNAME___. All rights reserved.
//
#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
46 changes: 46 additions & 0 deletions 21451198卢超/project4/Note/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// AppDelegate.m
// Note
//
// Created by jiaoshoujie on 14-11-21.
// Copyright (c) 2014年 ___FULLUSERNAME___. All rights reserved.
//

#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
168 changes: 168 additions & 0 deletions 21451198卢超/project4/Note/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="5056" systemVersion="13D65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="LbO-dB-Kb7">
<dependencies>
<deployment defaultVersion="1536" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
<scenes>
<!--Note List Table View Controller - 记事本-->
<scene sceneID="8nu-QR-Due">
<objects>
<tableViewController id="Upr-rf-9Oz" customClass="NoteListTableViewController" sceneMemberID="viewController">
<tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="gOf-hT-XsI">
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="NoteCell" textLabel="XsM-e0-Sgs" detailTextLabel="rNu-g1-Ya4" style="IBUITableViewCellStyleSubtitle" id="KIL-E7-TCO">
<rect key="frame" x="0.0" y="86" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KIL-E7-TCO" id="Bns-sp-Ihq">
<rect key="frame" x="0.0" y="0.0" width="287" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="XsM-e0-Sgs">
<rect key="frame" x="15" y="3" width="34" height="22"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="18"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="left" text="Detail" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="rNu-g1-Ya4">
<rect key="frame" x="15" y="25" width="32" height="15"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
<connections>
<segue destination="NwF-tG-3cM" kind="push" identifier="showNoteDetailsSegue" id="0Wm-7R-yzN"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="Upr-rf-9Oz" id="vle-om-c5d"/>
<outlet property="delegate" destination="Upr-rf-9Oz" id="DfE-ZG-zYd"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="记事本" id="Tdr-a4-sJi">
<barButtonItem key="rightBarButtonItem" systemItem="add" id="g3o-UN-Uhd">
<connections>
<segue destination="OWB-QW-nlT" kind="push" identifier="addNewNoteSegue" customClass="UIStoryboardPopoverSegue" id="rIE-rj-6c8"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="notesTableView" destination="gOf-hT-XsI" id="mNr-Iw-Udg"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="xbJ-yC-X6M" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1431" y="87"/>
</scene>
<!--Add Note View Controller - 新建记事-->
<scene sceneID="26V-vh-FMm">
<objects>
<viewController id="OWB-QW-nlT" customClass="AddNoteViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="la9-Bg-ryl"/>
<viewControllerLayoutGuide type="bottom" id="uTq-0V-51Y"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="N8I-dK-oYc" customClass="UIControl">
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="VJu-CN-dxI">
<rect key="frame" x="0.0" y="62" width="320" height="418"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<connections>
<action selector="backgroundTap:" destination="OWB-QW-nlT" eventType="touchDown" id="Xo5-6o-znp"/>
</connections>
</view>
<navigationItem key="navigationItem" title="新建记事" id="g92-kF-B3z">
<barButtonItem key="rightBarButtonItem" title="完成" id="Hy8-y4-ZVp">
<connections>
<action selector="addNoteAction:" destination="OWB-QW-nlT" id="osQ-wE-bsL"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="rightButon" destination="Hy8-y4-ZVp" id="yeA-7O-94g"/>
<outlet property="textView" destination="VJu-CN-dxI" id="IdC-Eu-rWE"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="lJH-KQ-HNm" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1898" y="339"/>
</scene>
<!--Show Note View Controller - Title-->
<scene sceneID="89q-1J-4zT">
<objects>
<viewController id="NwF-tG-3cM" customClass="ShowNoteViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="bXD-UZ-9ZQ"/>
<viewControllerLayoutGuide type="bottom" id="LaF-1Z-qio"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Qwl-lR-Ehq" customClass="UIControl">
<rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wPv-YU-f6d">
<rect key="frame" x="0.0" y="65" width="320" height="415"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<connections>
<action selector="backgroundTap:" destination="NwF-tG-3cM" eventType="touchDown" id="kGl-QC-gVR"/>
</connections>
</view>
<navigationItem key="navigationItem" title="Title" id="MW8-U5-RKt">
<barButtonItem key="rightBarButtonItem" title="完成" id="SKs-An-20m">
<connections>
<action selector="updateNotesAction:" destination="NwF-tG-3cM" id="n08-1O-dxm"/>
</connections>
</barButtonItem>
</navigationItem>
<connections>
<outlet property="noteNavItem" destination="MW8-U5-RKt" id="c0J-sN-R6L"/>
<outlet property="noteTextView" destination="wPv-YU-f6d" id="agI-7w-Uig"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="DbJ-yU-bli" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1898" y="-227"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="onT-oK-RQm">
<objects>
<navigationController definesPresentationContext="YES" id="LbO-dB-Kb7" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="Kdg-M9-F1G">
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
<segue destination="Upr-rf-9Oz" kind="relationship" relationship="rootViewController" id="bNl-7w-Jpu"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="7WT-CC-amJ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1015" y="87"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
</document>
Loading