3

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

- (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

我使用上述方法来查看控制台中的进度。但是我如何使用“进度条”在 nib 文件中做到这一点?

4

1 回答 1

15

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

float progress = [[NSNumber numberWithInteger:totalBytesWritten] floatValue];
float total = [[NSNumber numberWithInteger: totalBytesExpectedToWrite] floatValue];
progressView.progress = progress/total;
于 2009-10-31T16:33:26.073 回答