pkluz / PKHUD

A Swift based reimplementation of the Apple HUD (Volume, Ringer, Rotation,…) for iOS 8.
MIT License
3.79k stars 494 forks source link

Call HUD.show() in the viewDidLoad() method #216

Closed aguidis closed 6 years ago

aguidis commented 6 years ago

I experienced a similar issue with the last version.

While I fetch the content to display (async task) in myCollectionViewController, I would like to show the HUD loader so I called:

PKHUD.sharedHUD.contentView = PKHUDSystemActivityIndicatorView()
PKHUD.sharedHUD.show()

in the viewDidLoad() method just after my async task and I have the same error : Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

is it possible to show the loader while an async task is in progress ?

image
aguidis commented 6 years ago

@PGLongo explained in this issue that "In the root VC swift UIApplication.shared.keyWindow is nil, so you have to specify manually the view, or show the HUD in viewDidAppear".

I don't why I didn't try it before, anyway, the solution was to add an argument when calling the show() method: PKHUD.sharedHUD.show(onView: self.view)