iosswiftsvprogresshud

SVProgressHUD doesnt show after showing another message


I'm trying to show a spinner with SVProgressHUD, and when i get a async response from a server, dismiss that hud and show another hud with the message recevied from the server.

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    SVProgressHUD.setDefaultStyle(.Custom)
    SVProgressHUD.setForegroundColor(UIColor.whiteColor())
    SVProgressHUD.setBackgroundColor(UIColor.clearColor())
    SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.Clear)
    SVProgressHUD.show()
    loadData()

}

private func loadData() {
    ApiService.getData { (succeed, message) -> () in
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            self.dismissHud()
        })
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            SVProgressHUD.showInfoWithStatus("I can't see this")
        })
}

If i remove the code in viewDidAppear that shows the HUD i can see the message. Any ideas? Thx

enter image description here


Solution

  • Two things are wrong, first why dispatch to the same thread twice? and second if you want to just show the HUD don't dismiss it.

    The SVProgressHUD.showInfoWithStatus will hide the message after some time.
    The reason you are not seeing the seconde HUD is because it is still remove the first one. Since you just want to update don't call the dismiss.