简体   繁体   中英

UIProgressView is not updating, but the title is

This one is a real head scratcher, I am using an operation queue like so:

let queue = OperationQueue()
queue.qualityOfService = .userInteractive
queue.addOperation {
    generator = BillGenerationv3(procedures: procedure)
        batchPrinting = true
        if generator!.generateBills(pInfo: pInfo, cInfo: cInfo, view: self) {
            DispatchQueue.main.async { // Correct
            self.progressBar.progress = Float(count/uidPrecentage)
            self.title = "Batching Claims \(count)/\(uidPrecentage)...Please Wait"
            nextClaim()
        }                                
  }
}

It updates the title perfectly, yet the progress bar does nothing until the end. What am I doing wrong?

let someInt: Int = 3
let someOtherInt: Int = 5

This will not work

print(Float(someInt/someOtherInt))

//"0.0"

This will

print(Float(someInt)/Float(someOtherInt))

//"0.6"

The reason being that in the first scenario you're initializing a Float with the result of integer division which causes the result to be rounded to an integer by the nature of the operation.

The second scenario involves explicitly dividing two floating point numbers so the result will therefore also be a float and handle decimal numbers.

First of all, make sure your values count and uidPrecentage return valid ones (according to your estimations) and the calculus is 0 <= value <= 1 .

Last but certainly not least, you should be using the progress view's class method setProgress(_ progress: Float, animated: Bool) to update it instead of modifying directly the variable. As seen in the official documentation https://developer.apple.com/documentation/uikit/uiprogressview/1619846-setprogress , it even hands you for free the progress animation should you want

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM