所以我知道你應該在主線程上做你的更新。我使用蘋果的代碼寫我們的數據庫做文件目錄:調試主線程iPhone上的UI更新,活動指示器不旋轉
// 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];
,我確實看到了我的活動指標。有沒有一種方法來調試,看看發生了什麼,爲什麼我沒有看到我的旋轉指標?謝謝。
你應該這樣做**在主線程上更新UI **。如果您有大量非UI工作,則可以使用performSelectorInBackground在後臺執行此操作,或者可以使用GCD和塊,以稍後在UI線程上或在後臺 – Nate 2012-07-12 23:18:16