1

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

Godfather
  • 4,040
  • 6
  • 43
  • 70
  • i think your `dissmisshud` code hide all the hud which is show in windows. and may be `shoinfowithstatus` call before `dissmisshud` method, Plz check through break point. – Ilesh P Sep 14 '15 at 13:30
  • Nope, line 33 is exectued before 36. I also tried showing the hud just after calling dismissHud(). – Godfather Sep 14 '15 at 13:34
  • 1
    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. – rckoenes Sep 14 '15 at 13:34
  • On the top of my mind... Retain cycle? Add `[weak self]` in front of `(succeed, message ... `, maybe self is no longer available. (although, it would crash though I think) – Paul Peelen Sep 14 '15 at 13:36
  • rckones, you were right, if i dont dismiss the hud i can show another message. And yeah, doesnt make any sense dispatch to the same thread twice, sorry. – Godfather Sep 14 '15 at 13:37

2 Answers2

2

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.

rckoenes
  • 69,092
  • 8
  • 134
  • 166
0

I have change FadeInAnimationDuration and FadeoutAnimationDuration to 0.0 and it works fine for me. I am using HUD like this :

To Show HUD :

func showActivityLoader() {

            dispatch_async(dispatch_get_main_queue(), {

            SVProgressHUD.setFadeInAnimationDuration(0.0)
            SVProgressHUD.setFadeOutAnimationDuration(0.0)
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.Clear)
            SVProgressHUD.show()

            })
    }

To Hide HUD :

func dismissActivityLoader() {

            dispatch_async(dispatch_get_main_queue(), { 

                SVProgressHUD.dismiss()
            })
    }
technerd
  • 14,144
  • 10
  • 61
  • 92