下载图片时的进度条

发布于 2024-09-06 18:34:03 字数 745 浏览 0 评论 0原文

我将如何添加进度条来下载大图像或任何与此相关的文件?这是我的代码:

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                             NSUserDomainMask, YES);

        NSString *docsPath = [paths objectAtIndex:0];
        NSString *downloadPath = [[[NSString alloc]initWithFormat:@"http://www.zzz.com/%@.jpg",chartFileName]autorelease];
        NSString *savePath = [[[NSString alloc]initWithFormat:@"%@/%@.jpg",docsPath, chartFileName]autorelease];
        NSURL *url = [[NSURL alloc]initWithString:downloadPath];
        NSData *downloadedChartData = [NSData dataWithContentsOfURL:url];
        [url release];
        [downloadedChartData writeToFile:savePath atomically:YES];

How would I go about adding a progress bar for downloading a large image, or any file for that matter? here is my code:

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                             NSUserDomainMask, YES);

        NSString *docsPath = [paths objectAtIndex:0];
        NSString *downloadPath = [[[NSString alloc]initWithFormat:@"http://www.zzz.com/%@.jpg",chartFileName]autorelease];
        NSString *savePath = [[[NSString alloc]initWithFormat:@"%@/%@.jpg",docsPath, chartFileName]autorelease];
        NSURL *url = [[NSURL alloc]initWithString:downloadPath];
        NSData *downloadedChartData = [NSData dataWithContentsOfURL:url];
        [url release];
        [downloadedChartData writeToFile:savePath atomically:YES];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九厘米的零° 2024-09-13 18:34:03

您可以在 NSURLConnection 调用中覆盖 connection:didReceiveData: 。请参阅此处了解更多信息:

如何将 NSURLConnection 与 UIProgressView 集成?

You could override connection:didReceiveData: in your NSURLConnection call. See here for more:

How to integrate NSURLConnection with UIProgressView?

如果没结果 2024-09-13 18:34:03

在后台运行选择器来检查图像的下载大小,并将其与所需的大小进行比较。然后将进度条的百分比设置为已下载/需要。

Run a selector in the background that checks the image's download size, and compares it against the required size. Then set the % of the progress bar to downloaded/required.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文