我想根据从服务器下载的数据量显示UIProgressbar。
我实现的一种方法是创建一个NSURLConnection并设置委托。 - (void)连接:(NSURLConnection *)连接didReceiveResponse:(NSURLResponse *)响应 给了我expectedContentLengh
在 - (void)连接中:(NSURLConnection *)连接didReceiveData:(NSData *)数据 我每次都会逐个获取数据,直到下载完所有数据。
但这并没有解决我的问题。
还有其他办法吗?
您的所有建议都表示赞赏。
由于
答案 0 :(得分:2)
如果你知道预期的内容长度,只需保持到目前为止收到的总数除以你将获得的总金额:
// These should be properties of the delegate class
UIProgressView * progressView;
long long expected;
long long gotSoFar;
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
gotSoFar += data.length;
progressView.progress = gotSofar / expected;
}
如果你在分区上获得了类型警告,那么在进行分割前很长一段时间。