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'?其他一切看起來都很複雜且沒有必要。 –