0

したがって、メインスレッドで更新を行う必要があることはわかっています。私は、ドキュメントディレクトリを実行するデータベースを作成するために Apple のコードを使用しています。

// Creates a writable copy of the bundled default database in the application Documents directory.
- (void)createEditableCopyOfDatabaseIfNeeded {
    // First, test for existence.
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"bookdb.sql"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success)
        return;
    // The writable database does not exist, so copy the default to the appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"bookdb.sql"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
    if (!success) {
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
    }
}

そうです

[activityIndicator startAnimating];
[self createEditableCopyOfDatabaseIfNeeded];

アクティビティ インジケータが表示されません。コメント アウトする[self createEditableCopyOfDatabaseIfNeeded];と、アクティビティ インジケーターが表示されます。これをデバッグして、何が起こっているのか、回転インジケーターが表示されない理由を確認する方法はありますか? ありがとう。

4

1 に答える 1

2

文脈から外れて言うのは難しいですが、アクティビティインジケーターがcreateEditableCopyOfDatabaseIfNeeded進行中の操作を表すことを望んでいると思います。がメインスレッドから呼び出されたとすると、次の[self createEditableCopyOfDatabaseIfNeeded]ようなことができます。

[activityIndicator startAnimating];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
    [self createEditableCopyOfDatabaseIfNeeded];
    dispatch_async(dispatch_get_main_queue(), ^{
        [activityIndicator stopAnimating];
    });
});
于 2012-07-12T23:15:17.673 に答える