iosdispatchmbprogresshud

MBProgressHUD 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 DispatchQueue.main block, the hud doesn't show:

override func viewDidLoad() {
   super.viewDidLoad()

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

I debug the view hierarchy, and there is a layout issue:

"Position and size are ambiguous for MBProgressHUD"

The navigationController is a childViewController of fatherViewController and the container view is set by auto layout in fatherViewController's view.

Is that cause the issue?


Solution

  • I have built a demo to test it, but it didn't occur. So I rechecked my code and found I put some work in DispatchQueue.main.async which block the UI and cause the problem.