我一直試圖讓這個工作一天,現在我仍然失敗。我想在安裝應用程序時將大量文件從軟件包複製到我的應用程序的「文檔」文件夾中,但這會讓用戶長時間等待應用程序顯示啓動畫面。UiAlertView與UIProgressView在本地複製文件
所以我想我會做一個初始的UIAlertView與UIProgressView作爲子視圖,每次將文件複製到文檔文件夾時得到更新。但是,警報顯示和進度欄永遠不會更新。我的邏輯是:
- 設置UIProgressView和UIAlertView作爲我的ViewController的實例變量。
- 在ViewDidLoad中,顯示警報並設置代理
在
- (void)didPresentAlertView:(UIAlertView *)alertView
中執行for循環,該循環複製文件並更新UI。代碼爲:- (void)didPresentAlertView:(UIAlertView *)alertView{ NSString *src, *path; src = // path to the Bundle folder where the docs are stored // NSArray *docs = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:src error:nil]; float total = (float)[docs count]; float index = 1; for (NSString *filename in docs){ path = [src stringByAppendingPathComponent:filename]; if ([[NSFileManager defaultManager]fileExistsAtPath:path]) { ... // Copy files into documents folder [self performSelectorOnMainThread:@selector(changeUI:) withObject:[NSNumber numberWithFloat:index/total] waitUntilDone:YES]; index++; } } [alertView dismissWithClickedButtonIndex:-1 animated:YES]; }
而對於ChangeUI代碼
- (void) changeUI: (NSNumber*)value{
NSLog(@"change ui %f", value.floatValue);
[progressBar setProgress:value.floatValue];
}
然而,這只是更新從0到1的UI,儘管打印的NSLog所有的中間值。有人在這裏知道我做錯了什麼嗎?
在此先感謝。
您是否嘗試過調用「 - (void)setProgress: – Stavash 2012-07-16 11:12:39
是的,但如果iOS <5.0,它會崩潰,這對我不利。 – 2012-07-16 11:31:37