How to use cocoa progress bars?

I am a new Mac programmer and I need help using NSProgressIndicator . I was already looking for sample code, but could not find anything that helped.

I want to do the following:

 -(IBAction)startProgressBar:(id)sender; { //I want to make the bar update itself by the value of 1 until it is at the value of 100 //Example: add 1 to bar every second until it is full } 
+4
source share
1 answer

I think performSelector:withObject:afterDelay will help you here.

Write a method that will increase your progress bar. At the end of this method, call performSelector:withObject:afterDelay on the same method with a delay of 1 second until the strip is full.

You probably won't need to pass an object to this method, so you can just use nil.

EDIT

In your case, I would recommend something like this:

 - (IBAction)startProgressBar:(id)sender { // Initialize the progress bar to go from 0 to 100 [progress setMinValue:0.0]; [progress setMaxValue:100.0]; [progress setDoubleValue:0.0]; // Start the auto-increment calls [self incrementProgressBar]; } - (void)incrementProgressBar { // Increment the progress bar value by 1 [progress incrementBy:1.0]; // If the progress bar hasn't reached 100 yet, then wait a second and call again if([progress doubleValue] < 100.0) [self performSelector:@selector(incrementProgressBar) withObject:nil afterDelay:1]; } 
+8
source

Source: https://habr.com/ru/post/1398662/


All Articles