How to check if a NSProgressIndicator is currently animated?
Asked Answered
M

2

6

NSProgressIndicator has methods called startAnimation: and stopAnimation:, but no method that I can find to check the state (whether it is currently animating or not). How would you do it?

Multiped answered 31/8, 2011 at 15:22 Comment(0)
C
1

You could just keep a BOOL value somewhere in your class that you set to YES or NO when you start and stop the animation respectively.

Casabonne answered 31/8, 2011 at 15:45 Comment(3)
I can. But I'd rather not subclass all the Cocoa classes I use :)Liman
Why would you have to subclass all of them? Can't you just keep a BOOL property in your delegate class or something? Or do you have more than one progress indicator?Casabonne
I have more than one, yes. Also, each object should keep information about its own state, not external classes.Liman
P
4

You should not be storing the state of a control in the control itself.

The progress indicator control doesn't provide access to its animated state because unlike something like a text field, the user can't change the state of the control. You will never be in a situation where the state of the control changes without your code initiating it. Because you are the one who sets the state of it, so you should keep track of it.

Cocoa uses the Model-View-Controller pattern and a progress indicator is a view. If you store state in the control then you are violating the MVC pattern.

Your View should reflect your Model at all times, and the Controller is there to ensure the view and model are kept in sync.

You should either use Cocoa Bindings to bind the animated state of your progress indicator to a BOOL stored in your model (preferred) or implement code in your controller class to control the animated state of the progress indicator when there is a change to a BOOL stored in your model.

Pater answered 31/8, 2011 at 23:20 Comment(2)
There does not appear to be a isAnimating property for for NSProgressIndicator (at least I can't find it in the docs), thus there is no way to use Cocoa Bindings for this :(Hirsh
It's the animate property.Pater
C
1

You could just keep a BOOL value somewhere in your class that you set to YES or NO when you start and stop the animation respectively.

Casabonne answered 31/8, 2011 at 15:45 Comment(3)
I can. But I'd rather not subclass all the Cocoa classes I use :)Liman
Why would you have to subclass all of them? Can't you just keep a BOOL property in your delegate class or something? Or do you have more than one progress indicator?Casabonne
I have more than one, yes. Also, each object should keep information about its own state, not external classes.Liman

© 2022 - 2024 — McMap. All rights reserved.