Iphone 是否可以在同一程序Xcode中打开2个sqlite数据库

Iphone 是否可以在同一程序Xcode中打开2个sqlite数据库,iphone,uiviewcontroller,Iphone,Uiviewcontroller,我有一个使用sqlite的应用程序。我从“资源”中的sqlite文件中读取表。我试图从另一个sqlite文件中读取表,但程序失败,出现以下错误 对于2012-04-10 14:12:14.331 SQL[1804:f803]*由于以下原因终止应用程序 未捕获异常“NSInternalInconsistencyException” 理由:“可以 未在bundle中加载NIB:'NSBundle 已加载名为的RootViewController 如果我不读取第一个sqlite文件,我可以读取第二个。

我有一个使用sqlite的应用程序。我从“资源”中的sqlite文件中读取表。我试图从另一个sqlite文件中读取表,但程序失败,出现以下错误

对于2012-04-10 14:12:14.331 SQL[1804:f803]*由于以下原因终止应用程序 未捕获异常“NSInternalInconsistencyException”

理由:“可以 未在bundle中加载NIB:'NSBundle 已加载名为的RootViewController

如果我不读取第一个sqlite文件,我可以读取第二个。如果我不读第二个,我可以读第一个。但是不能一起读


无法在同一程序中读取两个sqlite文件吗?

是的,您可以在一个项目中使用多个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文件。

是的,您可以在一个项目中使用多个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文件。

是的,可能是错误表明您的xib文件有问题。在加载第二个数据库时是否删除RootViewController.xib?对,问题与SQLite无关。根视图控制器有问题。是的,可能是,错误表明您的xib文件有问题。在加载第二个数据库时是否删除RootViewController.xib?对,问题与SQLite无关。问题在于根视图控制器。