NSProgressIndicator animation and redraw

Q: Why doesn't my NSProgressIndicator redraw every time I update it's value?

A: When an update to NSProgressIndicator is needed, when its value changes, or you call animate:, an event to redraw the view is added to the event queue and will be processed the next time events for that view are dispatched.

To ensure the progress bar redraws at once, you need to call:

[progressIndicator displayIfNeeded];

This will force pending events out of the standard queue and have them reflected on-screen immediately.

Listing 1: Example of using NSProgressIndicator control in a loop.

[progressIndicator setMaxValue: (double)count];
//...
for (loopIndex = 0; loopIndex < count; loopIndex++)
{
     // do some work...
     [progressIndicator setDoubleValue: (double)loopIndex];
     [progressIndicator displayIfNeeded];
}

Document Revision History

DateNotes
2006-11-15First Version

Posted: 2006-11-15


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.