MBProgressHUD do not show

When I write like this, it works as expected:

override func viewDidLoad() {
   super.viewDidLoad()
   MBProgressHUD.showAdded(to: navigationController!.view, animated: true)
}

However, when I put it in the DispatchQueue.main block, the hud does not show:

override func viewDidLoad() {
   super.viewDidLoad()

   DispatchQueue.main.async {
      MBProgressHUD.showAdded(to: self.navigationController!.view, animated: true)
   }
}

I am debugging the view hierarchy, and there is a problem with the layout:

"Position and size are ambiguous for MBProgressHUD"

NavigationController is a childViewController from fatherViewController, and the container view is set automatically by the location in fatherViewController.

This is problem?

+4
source share
4 answers

, . , DispatchQueue.main.async, .

+3

, :

override func viewDidLoad() {
   super.viewDidLoad()

   DispatchQueue.main.async {
      MBProgressHUD.showAdded(to: self.navigationController!.view, animated: true)
   }
}

-

+2

UIView (viewDidLayoutSubviews ) viewDidLoad. viewDidAppear. , DispatchAsync.main, , , .

+1

MBProgressHUD , .

: -

 override func viewDidLoad() {
       super.viewDidLoad()
       DispatchQueue.main.async {  start()
 }
}
func start(){


  MBProgressHUD.showAdded(to: self.navigationController!.view, animated: true)}
0

Source: https://habr.com/ru/post/1679837/


All Articles