ViewController.m
#import "ViewController.h" @interface ViewController () { NSString *todoTitleText; } @property NSString *db_path; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // パスとDBファイル名を指定 NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *dir = [paths objectAtIndex:0]; NSString *db_path = [dir stringByAppendingPathComponent:@"tr_todo.db"]; FMDatabase *db = [FMDatabase databaseWithPath:db_path]; // DBのパスを表示 NSLog(@"db path : %@",db_path); // テーブルを作成 NSString *sql = @"CREATE TABLE IF NOT EXISTS tr_todo (todo_id INTEGER PRIMARY KEY , todo_title TEXT ,todo_contents , created , modified , limit_date ); "; [db open]; // SQLを実行 [db executeUpdate:sql]; [db close]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)titleReturnKey:(id)sender { todoTitleText = self.titleField.text; NSLog(@"%@",todoTitleText); FMDatabase *db = [FMDatabase databaseWithPath:_db_path]; NSString *sql = @"INSERT INTO tablename (tr_todo) VALUES (?)"; [db open]; [db executeUpdate:sql, @"入れるデータ"]; [db close]; } @end
実現したいこと
※ TextFieldで値を入力後returnキータップでDBにInsertしたい
問題点
※DBのPathが取得できない
※入れるデータのところにTextFilidの値を指定するにはどうしたらいいでしょうか。
どなたかご教示いただけましたら幸いです。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。