Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fibo

macrumors newbie
Original poster
Nov 14, 2009
1
0
hello,

I would like to use the progress bar indicator to display how long the function crypto() takes.
The progress bar does not really work.
Can you please help me to correct it. Thank you

PHP:
- (IBAction)crypto:(id)sender1 {

	[progress setMinValue:0];
	[progress setMaxValue:100];
	[progress incrementBy:10];
	
crypto();

	for (int i = 0; i <= 100; i = i + 10) {
		[progress setDoubleValue:i];
		[progress displayIfNeeded];
		NSLog(@"%d", i);
	}


}
 
So, here's what your code is doing currently, in the order it occurs:

1) set up a progress bar
2) do all of crypto()
3) set the progress bar to all of its possible values in turn
4) return control to Cocoa, allowing it to update the progress bar

You'll need to either run crypto() on another thread, or (more likely) break crypto() into chunks and report progress after each chunk is done. Something like (this is totally untested):
Code:
- (void) runCryptoForAWhile {
    /* do the next 10% of the work of crypto() */
    [progress setDoubleValue:[progress doubleValue] + 10];
    if (/* some conditional indicating that crypto isn't finished */) {
        [self performSelector:@selector(runCryptoForAWhile) afterDelay:0]; //0 delay indicates "return control to the Cocoa runloop, but then run this as soon as possible after that"
    }
}
 
So, here's what your code is doing currently, in the order it occurs:

1) set up a progress bar
2) do all of crypto()
3) set the progress bar to all of its possible values in turn
4) return control to Cocoa, allowing it to update the progress bar

You'll need to either run crypto() on another thread, or (more likely) break crypto() into chunks and report progress after each chunk is done. Something like (this is totally untested):
Code:
- (void) runCryptoForAWhile {
    /* do the next 10% of the work of crypto() */
    [progress setDoubleValue:[progress doubleValue] + 10];
    if (/* some conditional indicating that crypto isn't finished */) {
        [self performSelector:@selector(runCryptoForAWhile) afterDelay:0]; //0 delay indicates "return control to the Cocoa runloop, but then run this as soon as possible after that"
    }
}

Correct me if I'm wrong, but wouldn't the double go from 0.0 (as 0%) to 1.0 (as 100%)?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.