我想在我的應用程序中實現一個進度條。發生的過程是應用程序將目錄複製到iOS文檔目錄中。通常需要7-10秒(iPhone 4測試)。我對進度條的理解是當事情正在發生時更新吧。但是基於目錄代碼的複製,我不知道如何知道它有多遠。UIProgressView酒吧在過程中
任何人都可以提供任何建議或例子如何做到這一點?進度條碼在下面並且複製目錄代碼。
謝謝!
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle: UIProgressViewStyleBar];
progressView.progress = 0.75f;
[self.view addSubview: progressView];
[progressView release];
//Takes 7-10 Seconds. Show progress bar for this code
if (![fileManager fileExistsAtPath:dataPath]) {
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSString *imageDataPath = [bundlePath stringByAppendingPathComponent:_dataPath];
if (imageDataPath) {
[fileManager copyItemAtPath:imageDataPath toPath_:dataPath error:nil];
}
}
看到這個線程:http://stackoverflow.com/questions/10414802/how-顯示進度的複製一個大文件在ios – Amit 2013-05-06 06:12:17
@ amit3117謝謝阿米特!我是新來的Objective-C,我如何根據鏈接的建議啓動單獨的線程?謝謝 – Teddy13 2013-05-06 06:14:21
通過調用啓動一個計時器:[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(targetMethod :) userInfo:nil repeatats:YES];這會在0.5秒內回覆targetMethod。那麼您可以更新在targetMethod中複製的進度條計算百分比,如下面的答案所示。 – Amit 2013-05-06 06:24:00