Cococa Touch 中的 UIProgressbar
我想根据从服务器下载的数据量显示 UIProgressbar。
我实现的一种方法是创建一个 NSURLConnection 并设置委托。 - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 给了我预期的ContentLengh
并且在 - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data 我每次都会一部分一部分地获取数据,直到下载完所有数据。
但这并没有解决我的问题。
还有其他方法可以做到这一点吗?
感谢您的所有建议。
谢谢
I want to display an UIProgressbar depending on the amount of data downloaded from the server.
One way I implemented is I made a NSURLConnection and set the delegate.
The - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
gave me the expectedContentLengh
And in the - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
I am getting the data part by part every time until all the data are downloaded.
But this did not solve my problem.
Is there any other way to do this ?
All your suggestions are appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您知道预期的内容长度,只需将迄今为止收到的内容除以您将获得的总数进行汇总即可:
如果您在除法上收到类型警告,请在进行除法之前将每个 long long 强制转换。
If you know the expected content length, just keep a running total of how much you've received so far divided by the total amount you'll get:
If you get type warnings on the division, cast each long long before doing the division.