UIProgressView 没有更新,但标题是
UIProgressView is not updating, but the title is
这个真是让人头皮发麻,我正在使用这样的操作queue:
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()
}
}
}
它完美地更新了标题,但是进度条直到结束才没有任何反应。我做错了什么?
首先,确保你的值 count
和 uidPrecentage
return 有效(根据你的估计)并且微积分是 0 <= 值<= 1。
最后但同样重要的是,您应该使用进度视图的 class 方法 setProgress(_ progress: Float, animated: Bool)
来更新它,而不是直接修改变量。正如官方文档中所见https://developer.apple.com/documentation/uikit/uiprogressview/1619846-setprogress,它甚至可以免费为您提供您想要的进度动画
let someInt: Int = 3
let someOtherInt: Int = 5
这行不通
print(Float(someInt/someOtherInt))
//"0.0"
这将
print(Float(someInt)/Float(someOtherInt))
//"0.6"
原因是在第一种情况下,您使用整数除法的结果初始化 Float,这会导致结果根据操作。
第二种情况明确涉及除以两个浮点数,因此结果也将是一个浮点数并处理十进制数。
这个真是让人头皮发麻,我正在使用这样的操作queue:
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()
}
}
}
它完美地更新了标题,但是进度条直到结束才没有任何反应。我做错了什么?
首先,确保你的值 count
和 uidPrecentage
return 有效(根据你的估计)并且微积分是 0 <= 值<= 1。
最后但同样重要的是,您应该使用进度视图的 class 方法 setProgress(_ progress: Float, animated: Bool)
来更新它,而不是直接修改变量。正如官方文档中所见https://developer.apple.com/documentation/uikit/uiprogressview/1619846-setprogress,它甚至可以免费为您提供您想要的进度动画
let someInt: Int = 3
let someOtherInt: Int = 5
这行不通
print(Float(someInt/someOtherInt))
//"0.0"
这将
print(Float(someInt)/Float(someOtherInt))
//"0.6"
原因是在第一种情况下,您使用整数除法的结果初始化 Float,这会导致结果根据操作。
第二种情况明确涉及除以两个浮点数,因此结果也将是一个浮点数并处理十进制数。