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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:28:14+00:00 2026-05-30T17:28:14+00:00

Hello I have a stopwatch in my app. I have a start, stop and

  • 0

Hello I have a stopwatch in my app.

I have a start, stop and reset button with the stopwatch.

The stop and reset buttons work

The start works sort of.

When a user first clicks on the start button it starts the stopwatch. If they click on the stop button then click back on the start button, it starts the stopwatch all over again.

What am I missing (code listed below)?

.h

    IBOutlet UILabel *stopWatchLabel;
    NSTimer *stopWatchTimer; // Store the timer that fires after a certain time
    NSDate *startDate; // Stores the date of the click on the start button
    @property (nonatomic, retain) IBOutlet UILabel *stopWatchLabel;
    - (IBAction)onStartPressed;
    - (IBAction)onStopPressed;
    - (IBAction)onResetPressed;
    - (void)updateTimer

.m

    - (void)updateTimer{

    NSDate *currentDate = [NSDate date];
    NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
    NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"HH:mm:ss:SSS"];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
    NSString *timeString=[dateFormatter stringFromDate:timerDate];
    stopWatchLabel.text = timeString;

    }

    - (IBAction)onStartPressed {
    startDate = [NSDate date];

    // Create the stop watch timer that fires every 10 ms
    stopWatchTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0
                                                  target:self
                                                selector:@selector(updateTimer)
                                                userInfo:nil
                                                 repeats:YES];
    }

    - (IBAction)onStopPressed {
    [stopWatchTimer invalidate];
    stopWatchTimer = nil;
    [self updateTimer]; 
    }

    - (IBAction)onResetPressed {
    stopWatchLabel.text = @"00:00:00:000";
    }

Any help would be great.

Cheers

  • 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-30T17:28:15+00:00Added an answer on May 30, 2026 at 5:28 pm

    In above code you are storing the time elapsed during start-stop action. To do this you will need NSTimeInterval totalTimeInterval variable in at class level. Initially or when reset button is pressed its value will be set to 0. In updateTimer method you will need to replace following code.

    NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
    totalTimeInterval += timeInterval;
    NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:totalTimeInterval ];
    

    Thanks,

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

Sidebar

Related Questions

hello i have a app that connects and post to user wall but when
Hello i have a TextField on my scene. It haves only digits, user input
Hello i have class for download file. He work as expected except for remove
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello I have in my app a modal view controller which when a certain
Hello have to start a new Activity from the BroascastReceiver or the Service, but
Hello I have an example that works properly: $(function() { $(#treegrid).jqGrid({ url: 'tree2.json', datatype:
Hello I have a table on which I have denied SELECT privs to a
Hello I have the following code namespace ConsoleApplication2 { class Program { static void
Hello I have been having trouble with this for a while now. I have

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.