2009-12-02 63 views
1

我想显示一个UIProgressbar,具体取决于从服务器下载的数据量。Cococa Touch中的UIProgressbar

我实现的一种方法是我做了一个NSURLConnection并设置委托。 的 - (无效)连接:(NSURLConnection的*)连接didReceiveResponse:(NSURLResponse *)响应 给我的expectedContentLengh

而在 - (无效)连接:(NSURLConnection的*)连接didReceiveData:(NSData的*)数据 我每次都会逐个获取数据,直到下载所有数据。

但这并没有解决我的问题。

有没有其他方法可以做到这一点?

所有的建议,表示赞赏。

感谢

回答

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; 
} 

如果您在师之前得到类型警告,在分裂之前每个人都会投入很长时间。