0

こんにちは、新しい iPhone プログラマーです。

sqlite データベースに接続しようとしていますが、問題があります。sqlite ライブラリがあり、サポート ファイル フォルダーにデータベース ファイルがあります。シミュレーターをロードしても接続しません。

 (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *docsDir;
        NSArray *dirPaths;

         //Get the documents directory
         dirPaths =          NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

  docsDir = [dirPaths objectAtIndex:0];

        //Builds the path to the database file
        databasePath = [[NSString alloc]
        initWithString:[docsDir                    stringByAppendingPathComponent:@"PetrolWatch.sqlite"]];

        NSFileManager *fileMgr = [NSFileManager defaultManager];

              if([fileMgr fileExistsAtPath:databasePath]== YES)
              {
               lblStatus.text = @"Path Exists";

              }
              else
              {
              lblStatus.text = @"Failed to open db";
              }

}

前もって感謝します

4

1 に答える 1

1

リソースがアプリケーションバンドルにロードされ、手動でドキュメントディレクトリにコピーされているにもかかわらず、ドキュメントディレクトリでSQLiteファイルを探しています。ファイルをバンドルから移動するコードが表示されないため、ファイル[[NSBundle mainBundle]pathForResource:]の存在を確認するためのより有益な方法になる可能性があります(nil path =リソースなし)。

于 2012-11-25T10:03:19.773 に答える