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 回答