自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

解決Sqlite在IOS應用中使用方法案例實現(xiàn)

移動開發(fā) iOS
Sqlite在IOS應用中如何應用是本文要介紹的內容,主要是來了解IOS應用中sqlite的使用方法,具體內容的實現(xiàn),來看本文詳細代碼。

SqliteIOS應用中如何應用是本文要介紹的內容,主要是來了解IOS應用sqlite的使用方法,sqlite數(shù)據(jù)庫初始化,復制到用戶目錄,并判斷是否數(shù)據(jù)庫已經(jīng)存在,或者復制是否成功!

在AppDelegate.m中輸入以下代碼,以便復制預置數(shù)據(jù)庫到指定doucment目錄

  1. - (BOOL) initializeDb {  
  2. NSLog (@"initializeDB");  
  3. // look to see if DB is in known location (~/Documents/$DATABASE_FILE_NAME)  
  4. //START:code.DatabaseShoppingList.findDocumentsDirectory  
  5.  
  6. NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
  7.  
  8. NSString *documentFolderPath = [searchPaths objectAtIndex: 0];  
  9. //查看文件目錄  
  10. NSLog(@"%@",documentFolderPath);  
  11. dbFilePath = [documentFolderPath stringByAppendingPathComponent:@"shopping.db"];  
  12. //END:code.DatabaseShoppingList.findDocumentsDirectory  
  13. [dbFilePath retain];  
  14. //START:code.DatabaseShoppingList.copyDatabaseFileToDocuments  
  15. if (! [[NSFileManager defaultManager] fileExistsAtPath: dbFilePath]) {  
  16. // didn't find db, need to copy  
  17. NSString *backupDbPath = [[NSBundle mainBundle] pathForResource:@"shopping" ofType:@"db"];  
  18. if (backupDbPath == nil) {  
  19. // couldn't find backup db to copy, bail  
  20. return NO;  
  21. } else {  
  22. BOOL copiedBackupDb = [[NSFileManager defaultManager] copyItemAtPath:backupDbPath toPath:dbFilePath error:nil];  
  23. if (! copiedBackupDb) {  
  24. // copying backup db failed, bail  
  25. return NO;  
  26. }  
  27. }  
  28. }  
  29. return YES;  
  30. //END:code.DatabaseShoppingList.copyDatabaseFileToDocuments  
  31. NSLog (@"bottom of initializeDb");  
  32. }  
  33. - (void)applicationDidFinishLaunching:(UIApplication *)application {  
  34. // copy the database from the bundle if necessary  
  35. if (! [self initializeDb]) {  
  36. // TODO: alert the user!  
  37. NSLog (@"couldn't init db");  
  38. return;  
  39. }  
  40.     // Add the tab bar controller's current view as a subview of the window  
  41.     [window addSubview:tabBarController.view];  

小結:解決SqliteIOS應用中使用方法案例實現(xiàn)的內容介紹完了,希望通過本文能對你有所幫助!

責任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關推薦

2012-03-06 10:17:45

iOS SQLite3iOSSQLite3

2010-11-19 09:56:38

SQLiteAndroid

2011-05-17 16:20:46

C++

2011-03-30 10:41:11

C++數(shù)據(jù)庫

2023-01-28 17:41:07

Java代碼

2012-12-27 13:04:17

Android開發(fā)SQLite數(shù)據(jù)庫

2011-09-02 19:12:59

IOS應用Sqlite數(shù)據(jù)庫

2024-09-11 08:00:00

Java優(yōu)于反射開發(fā)

2012-02-13 14:22:22

MonoTouchiOS應用Visual Stud

2012-02-13 14:10:11

MonoTouchiOS應用Visual Stud

2011-07-29 11:10:56

IOS SimpleLogg 日志

2013-07-25 14:12:53

iOS開發(fā)學習UITableView

2011-08-19 10:01:09

iPhone應用SqliteUITableView

2021-02-25 11:19:37

谷歌Android開發(fā)者

2011-08-10 16:08:02

iPhoneProtocol協(xié)議

2012-01-18 14:14:29

iOS教程iOS5

2018-06-20 10:34:56

堆棧iOSswift

2023-12-22 09:11:45

AndroidNFC移動開發(fā)

2012-01-13 09:55:54

jQuery

2010-03-10 11:11:16

Python編程
點贊
收藏

51CTO技術棧公眾號