Search code examples
iosnstimeruiprogressview

working with UIProgressView to set progress bar to 30 minutes


I'm working on an project were I have put in a progress bar and then set a button to start the progressbar when it is pressed. The thing is that I want to have the progress in 30min when you pressed the startbutton, so I need help to set it to 30 minutes.

Here is my code to setup the progressbar and startbutton

the m-file

- (IBAction)StartButton:(id)sender {
    timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(moreProgress)
    userInfo:Nil repeats:YES];
    [super viewDidLoad];
    //progressbar start when button pressed
    }

and then i got this for the time

   //selector progress time
- (void) moreProgress {
    myProgressView.progress += 0.001;
}

Solution

  • I think it's only a math problem.

    First, myProgressView.progress can assume values from 0.0 to 1.0.

    As you call moreProgress each second, you'll need to call it 1800 times for 30 minutes. Thus, myProgressView.progress should increase 1/1800 by second.

    Change your code to:

    - (void) moreProgress {
        myProgressView.progress += 1.0/1800.0;
    }
    

    Hope it helps you! :)