将图像上传到我的服务器时显示进度条

时间:2009-10-31 10:38:53

标签: iphone progress-bar nsurlconnection

我的应用将图片上传到我的服务器。 我想通过进度条显示此事件。

- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

- (void)connectionDidFinishLoading:(NSURLConnection *)connection

我使用上面的方法来查看控制台中的prgressing。 但我如何使用'进度条'在nib文件中执行此操作?

1 个答案:

答案 0 :(得分:15)

如果您使用UIProgressView,您可以在连接中设置进度:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:这样的方法:

float progress = [[NSNumber numberWithInteger:totalBytesWritten] floatValue];
float total = [[NSNumber numberWithInteger: totalBytesExpectedToWrite] floatValue];
progressView.progress = progress/total;