我想在我的应用程序中实现一个进度条。发生的过程是应用程序将目录复制到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