Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 527
a_tuo Avatar asked Mar 09 '23 19:03

a_tuo


2 Answers

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.

like image 107
a_tuo Avatar answered Mar 19 '23 02:03

a_tuo


I performed test especially for you and following code works for me:

override func viewDidLoad() {
   super.viewDidLoad()

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

so the problem is somewhere else located

like image 37
Robert Avatar answered Mar 19 '23 02:03

Robert