在主线程上调试UI更新,iPhone,活动指示器未旋转



所以我知道你应该在主线程上进行更新。我正在使用苹果的代码编写我们的数据库做文档目录:

// 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];,我会看到我的活动指示器。有没有一种方法可以调试它,看看发生了什么,为什么我看不到我的旋转指示器?谢谢

断章取义,这很难说,但我假设您希望活动指示符表示正在进行的createEditableCopyOfDatabaseIfNeeded操作。假设[self createEditableCopyOfDatabaseIfNeeded]是从您的主线程调用的,您可以执行以下操作:

[activityIndicator startAnimating];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
    [self createEditableCopyOfDatabaseIfNeeded];
    dispatch_async(dispatch_get_main_queue(), ^{
        [activityIndicator stopAnimating];
    });
});

最新更新