Basic Countdown

Discussion in 'iOS Development' started by Axis, Jun 24, 2009.

  1. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    I want to have a countdown (minutes/seconds) that can be set by the user to update a UILabel. I know how to update the UILabel, but I would like to know the most efficient way to have a countdown for anything under, let's say, 15 minutes.

    How would I go about doing this?

    Thanks!

    Please Register or Log in to view images


    EDIT: I would prefer it to show milliseconds, if possible.\

    EDIT 2: I don't want it to be like "enter a date and see how many minutes". I want it to be more like the timer in the Clock application; the user sets the length of the countdown.
  2. Antonpup

    Antonpup Member

    Joined:
    Jan 31, 2009
    Messages:
    408
    Likes Received:
    0
    Device:
    iPhone 5 (Black)
    lol

    x=900
    while(x>0)
    {
    x=x-1
    }

    A simple code xD
  3. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    He wants it based on time.
  4. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    I'm sorry, I wasn't clear enough in my OP.

    I don't want it to be like "enter a date and see how many minutes". I want it to be more like the timer in the Clock application; the user sets the length of the countdown.
  5. Antonpup

    Antonpup Member

    Joined:
    Jan 31, 2009
    Messages:
    408
    Likes Received:
    0
    Device:
    iPhone 5 (Black)
    Well... Thats another question....

    Here's JavaScript for ya... you can easily compile it into whatever ur using...
    Code:
    function countdown() {
    	ActivateCountDown("CountDownPanel", 900);
    }
    900 = 15 mins in seconds.
  6. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    I found this:

    Code:
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(changeTime:) userInfo:nil repeats:YES];
    
    -(void)changeTime:(NSTimer *)theTimer{
    if(timeLeft==0){
            return;
    }
    else{
            timeLeft = timeLeft - 1;
            if(timeLeft==0){
                    [theTimer invalidate];
                    [self goToNextExercise];
            }
    }
    label.text = [NSString stringWithFormat:@"%i",timeLeft];
    }
    So, with that I could update my UILabel with timeLeft, right?
  7. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    Yep. Depending on the time interval you set in the NSTimer, the label will be updated more/less often.

Share This Page