koen
koen

Reputation: 5729

NSProgressIndicator not showing during app start up

This must be super simple, but I cannot find it.

I want to show an NSProgressIndicator indeterminite spinner style to my NSViewController to show in the middle of the view while the app starts up (similar to Xcode). Once all data is loaded (on a background thread), I return to the main thread and hide the spinner and show the contents.

Everything works as expected, except, I don't see the spinner.

In the storyboard I added the spinner as a sub view of the main view, and the added the centerX and centerY constraints, also in the storyboard.

enter image description here

enter image description here

Then in viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()

    progressSpinner.isHidden = false
    progressSpinner.startAnimation(self) // <-- do I use self here?
}

and once the data is loaded:

func didFinishLoading() {
    progressSpinner.stopAnimation(self) // <-- do I use self here?
    progressSpinner.isHidden = true

    showData()
}

What am I missing here?

Upvotes: 0

Views: 330

Answers (1)

koen
koen

Reputation: 5729

Ok, I found the problem. The "Hidden" checkbox in the storyboard was checked.

Even with progressSpinner.isHidden = false in viewDidLoad, the spinner remained invisible. Unchecking that box solved it.

enter image description here

EDIT

The underlying problem I think now is that spinner was obscured by the scrollView in the same window. Changing the order in the storyboard did not help, so I ended up removing and re-adding the spinner as shown below. And now it works independent of the Hidden checkbox setting.

override func viewDidLoad() {
    super.viewDidLoad()

    progressSpinner.removeFromSuperview()
    view.addSubview(progressSpinner, positioned: .above, relativeTo: nil)

    progressSpinner.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
    progressSpinner.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true

    progressSpinner.isHidden = false
    progressSpinner.isDisplayedWhenStopped = false

    progressSpinner.startAnimation(self)
}

Upvotes: 1

Related Questions