Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a NSProgressIndicator is currently animated?

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?

like image 772
F'x Avatar asked Aug 31 '11 15:08

F'x


1 Answers

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.

like image 107
Rob Keniger Avatar answered Oct 21 '22 01:10

Rob Keniger