Progress bar indicator

Discussion in 'Mac Programming' started by fibo, Nov 14, 2009.

  1. fibo macrumors newbie

    Joined:
    Nov 14, 2009
    #1
    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<= 10010) {
            [
    progress setDoubleValue:i];
            [
    progress displayIfNeeded];
            
    NSLog(@"%d"i);
        }


    }
     
  2. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #2
    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"
        }
    }
    
     
  3. Muncher macrumors 65816

    Muncher

    Joined:
    Apr 19, 2007
    Location:
    California
    #3
    Correct me if I'm wrong, but wouldn't the double go from 0.0 (as 0%) to 1.0 (as 100%)?
     
  4. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #4
    Try it and see. I'm pretty sure if he sets the max value to 100, it'll go to 100.
     
  5. Muncher macrumors 65816

    Muncher

    Joined:
    Apr 19, 2007
    Location:
    California
    #5
    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.
     

Share This Page