2012-04-10 17 views
2

我有一個使用sqlite的應用程序。我從'資源'中讀取來自sqlite文件的表格。我試圖從另一個源碼文件中讀取表,但該計劃失敗,以下錯誤可能在同一個程序中打開2個sqlite數據庫Xcode

for2012-04-10 14:12:14.331 SQL [1804:F803] *終止應用程序由於 未捕獲的異常' NSInternalInconsistencyException」,

原因: ': '一個NSBundle (加載)' 名爲'RootViewController的'

如果我不讀第一sqlite的文件,我也能 不在包中加載NIB閱讀本書條件。如果我不讀秒,我可以讀第一個。但不能一起閱讀。

是不是可以在同一個程序中讀取兩個sqlite文件?

+2

是的,這是可能的,錯誤說你有你的xib文件的問題。當您加載第二個數據庫時是否刪除RootViewController.xib? – 2012-04-10 12:32:57

+0

對,這個問題與SQLite無關。問題出在root視圖控制器上。 – Costique 2012-04-15 09:18:25

回答

0

是的,你可以在一個項目中使用多個SQLite文件。如果他們在你的文檔目錄,那麼你可以選擇作爲他們中的任何一個:

NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 

NSString* sqlfilePath = [documentsPath stringByAppendingPathComponent:@"file1.sqlite"]; 

BOOL file1Exists = [[NSFileManager defaultManager] fileExistsAtPath:sqlfilePath]; 

NSString* sqlfilePath = [documentsPath stringByAppendingPathComponent:@"file2.sqlite"]; 

BOOL file2Exists = [[NSFileManager defaultManager] fileExistsAtPath:sqlfilePath]; 


if(file1) 
{ 
    // do necessary operations here 
} 

else if (file2) 
{ 
    // do necessary operations here 
} 

然而,在你的情況,我認爲RootViewController是問題的原因,並沒有SQLlite文件。

相關問題