gpt4 book ai didi

ios - 如何在 moya swift 中添加进度 View ?

转载 作者:搜寻专家 更新时间:2023-11-01 06:29:18 24 4
gpt4 key购买 nike

如何在 moya swift 中添加进度 View ?,这样对吗。这是使用进度 block 的正确方法吗?

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()
}
}

最佳答案

您可以简单地将您的 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)
}
}

关于ios - 如何在 moya swift 中添加进度 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49548107/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com