I need to make an NSTimer
that will tell another class to fire in 10 seconds, and I would also like to use it to animate a determinate NSProgressIndicator
. I also need to know how to change my indeterminate progress indicator to determinate. I was able to find a Apple doc on this, however a more in-depth explanation would help.
linking a NSTimer to a NSProgressIndicator
2.3k views Asked by StackTrace At
2
There are 2 answers
0
On
Hope it helps.
Using the following way we can achieve what is expected
NSInteger progressValue;
NSTimer *timerObject;
progressValue = progressMaxValue;
timerObject = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(incrementProgressBar) userInfo:nil repeats:YES];
[timerObject fire];
[self.progressBar setMinValue:progressMinValue];
[self.progressBar setMaxValue:progressMaxValue];
[self.progressBar setDoubleValue:progressValue];
- (void)incrementProgressBar {
// Increment the progress bar value by 1
[self.progressBar incrementBy:1.0];
progressValue--;
[self.progressBar setDoubleValue:progressValue];
}
From indeterminate to determinate
NSProgressIndicator
You can change in IB. Select Your progressIndicator and go to Attributes inspector and uncheck Indeterminate checkbox like this:Or it can be done programatically:
Note: progressIndicatorOutlet is Your
NSProgressIndicator
outlet, so don't forget toIBOutlet
it.Determinate NSProgressIndicator animation:
It's very simple just set and change value like this:
Note: progressIndicatorOutlet is Your
NSProgressIndicator
outlet, so don't forget toIBOutlet
it.NSTimer:
Simple timer example:
Don't forget to add class which I mentioned in comments like this: