I\'m trying to refresh the progress bar in an UIProgressView for an upload request with NSURLConnection
. The goal is to refresh the progress bar while uploading a p
You should really read a C tutorial on numerical types. Presumably both totalBytesWritten
and totalBytesExpectedToWrite
are an integer type, so dividing them will result in truncation - that is, the fractional part of the result will be gone. Unless the result is at 100%, the integral part is always 0, so all those divisions will result in zero. Try casting one or both of the variables to float
or double
to get sensible results.
Also, UIProgressView
doesn't accept values between 0 and 100 by default but between 0 and 1. All in all, you should write
self.delegate.progressView.progress = ((float)totalBytesWritten / totalBytesExpectedToWrite);
and it should work fine.
Edit: the problem was that the data you were trying to upload was too small and it didn't need to be broken down to smaller chunks, so it was necessary to call this method only once. If you supply a great amount of data, then it will be able to be sent only in separate pieces, so the progress handler callback will be called multiple times.