show progress bar when uploadingan image to my server
my app upload an image to my server. i want to show this event by a progress bar.
- (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
i use this above methods to see the pr开发者_如何学Pythongressing in console. but how i do that in nib file using 'progress bar'?
If you use a UIProgressView you can set the progress in the connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite: method like this:
float progress = [[NSNumber numberWithInteger:totalBytesWritten] floatValue];
float total = [[NSNumber numberWithInteger: totalBytesExpectedToWrite] floatValue];
progressView.progress = progress/total;
精彩评论