Question

I'm having some issues with showing a progress indicator whenever a button is clicked, and then stop and hide the indicator when a NSTask is completed.

This should be the timeline: 1- Button clicked 2- shows progress indicator (from originally hidden state) 3- activates progress indicator 4- activate associated NSTask 5- Continue showing the indicator until the NSTask is completed 6- after the completion of the NSTask, hide the progress indicator.

I know how to get a progress indicator to animate etc. I just do not know how to combine these with the NSTask completing thing..

Thanks for the help in advance!

Was it helpful?

Solution

Use NSTask's terminationHandler property to set a block to execute when the task terminates. In that block stop/hide your progress indicator.

Addendum (see comments)

In rough outline:

NSTask *myTask = ...;
NSProgressIndicator *myIndicator = ...;

myTask.terminationHandler = ^(NSTask *theTask) { [myIndicator stopAnimation:nil]; };

Note that the handler is passed the NSTask in case it needs to access information from it. Also nil is passed as the sender to stopAnimation: - you usually pass self but that would cause a retain cycle and what object is actually invoking the method isn't important.

OTHER TIPS

You should be able to set a block to the NSTask's terminationHandler.

NSTask terminationHandler

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top