Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6109729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:26:13+00:00 2026-05-23T14:26:13+00:00

Ok my first app ever is a timer. Right after I made hello world

  • 0

Ok my first app ever is a timer. Right after I made hello world as the convention seems to be. I am using the NSTimer class as my timer and I fire it every second and then I change the text in a UILabel. Now this all works very good except for my very first run. Each time I run the app in the simulator and I start the timer their is a weird delay on my last second, it will freeze for about 2 seconds and then continue as if nothing is wrong. And it then works for every set that runs.

Here is the code where I set up the NSTimer:

theTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];

Then in the onTimer method I call updateLabel

countDownLabel.text = [NSString stringWithFormat:@"%02d:%02d", startMin,startSec];
//Check if sets are complete
if(setCount <= numOfSets)
{
    setLabel.text = [NSString stringWithFormat:@"Set %02d of %02d", setCount, numOfSets];
    //check if timer is complete
    if(startMin <= 0 && startSec <= 0)
    {
        countDownLabel.textColor = [UIColor greenColor];
        //run interval timer when timer is complete
        if(intervalBetweenSets <= intervalBetweenSetsSetting)
        {
            setLabel.text = [NSString stringWithFormat:@"Starting set"];
            intervalBetweenSets++;
            intervalCounterSec--;
            countDownLabel.text = [NSString stringWithFormat:@"00:%02d", intervalCounterSec];
        }
        else
        {
            //RESET values on timer label
            TimerSettings *myTimer = [TimerSettings sharedManager ];
            startMin = myTimer.min;
            startSec = myTimer.sec;
            intervalBetweenSets = 0;
            intervalCounterSec = intervalBetweenSetsSetting+1;
            countDownLabel.textColor = [UIColor redColor];
            countDownLabel.text = [NSString stringWithFormat:@"%02d:%02d", startMin,startSec];
            setLabel.text = [NSString stringWithFormat:@"Set %02d of %02d", setCount, numOfSets];
        }
    }
    else
    {
        //Actual timer for display
        if(startSec == 0)
        {
            startMin = startMin - 1;
        }
        startSec = startSec - 1;
        if(startSec == -1)
        {
            startSec = 59;
        }
        if(startMin <= 0 && startSec < 1)
        {
            //increment number of completed sets
            setCount++;
            //play sound when timer completes
            if (audioPlayer == nil)
                ;
            else
            {
                [audioPlayer play];
            }
        }

        countDownLabel.text = [NSString stringWithFormat:@"%02d:%02d", startMin,startSec];
    }
}

The thing is I don’t know if it is some problem with the timer or if it has something to do with my logic, if anything is unclear of what I am doing please ask away and I will clarify.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:26:14+00:00Added an answer on May 23, 2026 at 2:26 pm

    You shouldn’t use NSTimer to keep time if that is what you are trying to do, NSTimers are conceptually put into the event cue and so can only fire when your programming is waiting for input from the event cue. Yo can use NSTimers to tell you fields to update the display of itself but to get the amount of time passed you should either use NSDate methods or the equivelent C functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first winform app in .NET... I have made a couple of
Here's my two scenarios. 1 - User opens app for the first time ever
http://localhost:3000/genre I'm using Instant Rails, I'm introducing scaffolding for the first time ever. So
I am working on my first ever android app, and I'm creating basic exercise/calorie
Well, creating thumbnail images in an asp.net app seems more painful then I ever
I'm using two threads in an iPhone app for the first time and I've
I'm writing my first app with ASP.NET MVP (attempting Supervisory Controller) and Unit Testing
This is my first app with CI and I want to know whether $_POST
I am about to release my first app to the iTunes store. What version
I am new to Blackberry programming and starting my first app soon. I believe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.