所以我知道你应该在主线程上做你的更新。我正在使用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];
,我会看到我的活动指标。有没有办法调试这个以查看发生了什么以及为什么我看不到我的旋转指示器?感谢。
答案 0 :(得分:2)
脱离上下文,很难说,但我认为您希望活动指示符代表正在进行的createEditableCopyOfDatabaseIfNeeded
操作。假设从您的主线程调用[self createEditableCopyOfDatabaseIfNeeded]
,您可以执行以下操作:
[activityIndicator startAnimating];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[self createEditableCopyOfDatabaseIfNeeded];
dispatch_async(dispatch_get_main_queue(), ^{
[activityIndicator stopAnimating];
});
});