View Full Version : Progress bar indicator
fibo
Nov 14, 2009, 10:48 AM
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
- (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);
}
}
Catfish_Man
Nov 14, 2009, 01:47 PM
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):
- (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"
}
}
Muncher
Nov 15, 2009, 08:00 PM
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):
- (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%)?
Catfish_Man
Nov 15, 2009, 09:21 PM
Try it and see. I'm pretty sure if he sets the max value to 100, it'll go to 100.
Muncher
Nov 16, 2009, 12:28 AM
Try it and see. I'm pretty sure if he sets the max value to 100, it'll go to 100.
I know it would store 100. I'm asking about what the progress bar will accept as an input. I know on the iPhone progress bars take values from 0-1.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.