简体   繁体   English

如何在moya swift中添加进度视图?

[英]how to add progress view in moya swift?

how to add progress view in moya swift ?, is this correct. 如何在moya swift中添加进度视图?这是正确的。 is this a correct way to use progressblock. 这是使用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()
        }
    }

You can simple hide your LoadingHUD in the result closure only LoadingHUD在结果闭包中隐藏您的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)
    }
}

just modify the hideLoadingHud in inside the success or failure block. 只需修改成功或失败块内的hideLoadingHud bz that part result handler 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)

        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM