0
我想显示进度视图的文件,我下载时,我打印的进度是正确的,但是当我在进度视图上实现它是完全错误的,它会到3000这里是我的代码。我使用MHRadialProgressView链接UIProgressView显示下载进度使用Firebase
downloadTask.observe(.progress) { (snapshot) -> Void in
// Download reported progress
let percentComplete = 100 * Double(snapshot.progress!.completedUnitCount)/Double(snapshot.progress!.totalUnitCount)
print("percentComplete")
self.progressView.moveNext(currentprogress as NSNumber!)
// Update the progress indicator
}
当我用MBProgressHUD这里是它
downloadTask.observe(.progress) { (snapshot) -> Void in
// Download reported progress
let percentComplete = 100 * Float(snapshot.progress!.completedUnitCount)
/Float(snapshot.progress!.totalUnitCount)
let hud = MBProgressHUD.showAdded(to: (self.navigationController?.view)!, animated: true)
// Set the determinate mode to show task progress.
hud.mode = MBProgressHUDMode.determinate
hud.label.text = NSLocalizedString("Loading...", comment: "HUD loading title")
// Set up NSProgress
let progressObject = Progress(totalUnitCount: 100)
hud.progressObject = progressObject
// Configure a cancel button.
DispatchQueue.global(qos: .default).async(execute: {() -> Void in
// Do something useful in the background and update the HUD periodically.
while progressObject.fractionCompleted < 1.0 {
progressObject.becomeCurrent(withPendingUnitCount: 1)
progressObject.resignCurrent()
usleep(useconds_t(percentComplete))
}
DispatchQueue.main.async(execute: {() -> Void in
hud.hide(animated: true)
})
})
}
我收到此错误 nanfatal错误代码:无法转换为UInt32的浮动值,因为它要么是无穷的, NaN的
请检查上面的代码,当我使用MBProgressHUD我得到这个错误。 nanfatal错误:浮点值无法转换为UInt32,因为它是无限的或NaN – Khallad
你能解释为什么你不只是这样做:'hud.progressObject = snapshot.progress'?其他一切看起来都很复杂且没有必要。 –