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

  • SEARCH
  • Home
  • 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 9066623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:46:06+00:00 2026-06-16T16:46:06+00:00

I have a stopwatch that is working just fine on its own, but when

  • 0

I have a stopwatch that is working just fine on its own, but when I switch back from another view from the tab bar, the stopwatch does some weird things (tapping the back button on the navigation view works fine).

  1. The stopwatch label is hidden when the user switches back from the other tab, even though it should be visible when showing the view.

  2. If the stopwatch is running when the user taps on the other tab and taps on the stopwatch tab again, the stopwatch goes to -31:-23.-64, and the stop button (which should reset the timer and show the start button) won’t do anything when tapped.

  3. If the stopwatch is not running when the user taps on the other tab and taps on the stopwatch tab again, the stopwatch will start normally, but the stop button is not showing when the user taps the start button.

Here is my code:

.h:

@interface ViewController : UIViewController {
    IBOutlet UIButton *btnStart;
    IBOutlet UIButton *btnStop;
    IBOutlet UILabel *lblTimer;
    NSTimer *stopWatchTimer;
    NSDate *stopDate;
    NSDate *startDate;

}

@property (strong, nonatomic) IBOutlet UILabel *lblTimer;

- (IBAction)btnStart:(id)sender;
- (IBAction)btnStop:(id)sender;

.m:

- (void)updateTimer
{
    NSDate *currentDate = [NSDate date];
    NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
    NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"mm:ss.SS"];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
    NSString *timeString=[dateFormatter stringFromDate:timerDate];
    lblTimer.text = timeString;
}

- (IBAction)buttonStart:(id)sender {

    startDate = [NSDate date];

    // Create the stop watch timer that fires every 1ms
    stopWatchTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/100.0
                                                      target:self
                                                    selector:@selector(updateTimer)
                                                    userInfo:nil
                                                     repeats:YES];
    btnStop.hidden = NO;
    btnStart.hidden = YES;
}

- (IBAction)buttonStop:(id)sender {

    [self updateTimer];
    btnStop.hidden = YES;
    btnStart.hidden = NO;

    [stopWatchTimer invalidate];
    stopWatchTimer = nil;
}

Please let me know what I can do to fix this, or if anything else is needed.

  • 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-06-16T16:46:08+00:00Added an answer on June 16, 2026 at 4:46 pm

    First of all, it looks like startDate is messed up. The init is being called. It should probably just be [NSDate date].

    As for the view not appearing… after calculating the date, timer.text is being set to something. What is timer? Are you sure that shouldn’t be timer.title? And after you do that, you may need to [timer setNeedsDisplay] to make sure the text is updated on the control if that’s what you want.

    If the text is still messed up, try to update less often. Maybe every tenth second and see if the text behaves better.

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

Sidebar

Related Questions

I have a NSDate variable. From that variable, how I can show a stopwatch
I have some working code that I altered but I can't seem to get
So I'm trying to write a stopwatch app that displays time in milliseconds, but
I have an app with 2 threads (now), but it seems that function Thread.Sleep()
I'm developing something like a stopwatch, so I have to turn off that below
I am working on a very simple stopwatch using WPF but using the System.Diagnostics
I have three methods in c# that runs the same code but with a
I have a WCF service that uses LINQ to SQL for its data layer.
I'm working on a stopwatch style app that might be running for hours at
I have an NSTimer that acts for the basis of a stopwatch. - (void)startTimer

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.