如何在moya swift中添加进度视图?, 它是否正确。这是使用progressblock的正确方法。
let instance = MoyaProvider<ServiceType>()
self.view.showLoadingHUD()
instance.request(.GetRouteDetail, callbackQueue: DispatchQueue.main, progress: { (response) in
if response.completed{
self.view.hideLoadingHUD()
}else{
self.view.showLoadingHUD()
}
}) { (result) in
switch result{
case .success(let response):
print(response)
case .failure(let error):
print(error)
self.view.hideLoadingHUD()
}
}
答案 0 :(得分:2)
您可以在结果关闭中简单地隐藏LoadingHUD
let instance = MoyaProvider<ServiceType>()
self.view.showLoadingHUD()
instance.request(.GetRouteDetail, callbackQueue: DispatchQueue.main, progress: { (response) in
// You can update the progress percent ...here or ignore it
}) { (result) in
self.view.hideLoadingHUD()
switch result{
case .success(let response):
print(response)
case .failure(let error):
print(error)
}
}
答案 1 :(得分:1)
只需修改成功或失败块内的hideLoadingHud
即可。 bz那部分结果处理程序
let instance = MoyaProvider<ServiceType>()
self.view.showLoadingHUD()
instance.request(.GetRouteDetail, callbackQueue: DispatchQueue.main, progress: { (response) in
}) { (result) in
self.view.hideLoadingHUD()
switch result{
case .success(let response):
print(response)
case .failure(let error):
print(error)
}
}