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 906063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:19:24+00:00 2026-05-15T16:19:24+00:00

how to make timer counter zero in this particular code when I click on

  • 0

how to make timer counter zero in this particular code when I click on the reset button
the values must go to 00:00:00 and when i click on start button timer should be start from starting
please help out

code here
this in the .h file code

-(void)start
{
timer1 = [NSTimer scheduledTimerWithTimeInterval:(.01) target:self selector:@selector(timepassed) userInfo:nil repeats:YES];

}

this is in the .m file

-(void)timepassed
{

counter++;

     if (counter == 60)  { sec++; counter = 0; }
    if (sec == 60) { min++; sec = 0; }
    if (min == 60) { hr++; min = 0; }

NSString *l=[NSString stringWithFormat:@"%i:%i:%i",hr,min,sec];

[m setText:l];

}
  • 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-15T16:19:24+00:00Added an answer on May 15, 2026 at 4:19 pm

    If need a variable to control if timer is running or not, then your function would look like:

    -(void)timepassed 
    {
        if (isTimerRunning)
        {
            counter++;
    
            if (counter == 60)  { sec++; counter = 0; }
            if (sec == 60) { min++; sec = 0; }
            if (min == 60) { hr++; min = 0; }
        }
        NSString *l=[NSString stringWithFormat:@"%i:%i:%i",hr,min,sec];
    
        [m setText:l];
    }
    

    With “Start” and “Stop” buttons you would just change values of variable “isTimerRunning”.
    Action for button “Reset” should be set variables “sec”, “min”, “hr” to zero and if you would like to stop timer at the same time set “isTimerRunning” to no.

    Another thing that you should test in your application is accuracy, doing it like this (setting interval to 0.01 sec, and then updating counter) might be inaccurate.

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

Sidebar

Related Questions

I'm trying to make a timer count down from 5 seconds to zero before
I'm using this javascript to make images scroll vertically from the bottom till the
How do make a zero placeholder for the counter? My thought was an if
This error is inexplicably occurring. Here is the code and output: timer.cpp: #include timer.h
I want to make timer string with CCLabelAtlas. The problem is the character, :.
I'm trying to make a timer in c++. I'm new to c++. I found
I'm messing around with Xcode and Interface Builder. I want to make a timer
I want to make a WCF timer service where clients can register in order
Im trying to make a countdown timer run in the background of my activity,
Trying to make a small countdown timer in my app but it's not working.

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.