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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:59:37+00:00 2026-05-22T02:59:37+00:00

I have compiled the following code and there are no apparent runtime errors; however,

  • 0

I have compiled the following code and there are no apparent runtime errors; however, the display freezes at 00:00:01 when I run it. It works if I only display the seconds attribute. Does anyone see an apparent oversight that I have missed in this code? I know there is a potential memory leak with the start button, but I will fix that eventually.

Thanks in advance.

#import "StopwatchViewController.h"

@implementation StopwatchViewController

- (IBAction)start{

    //creates and fires timer every second
    myTimer = [[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(showTime) userInfo:nil repeats:YES]retain];
}
- (IBAction)stop{
    [myTimer invalidate];
    myTimer = nil;
}

- (IBAction)reset{

    [myTimer invalidate];
    time.text = @"00:00:00";
}

(void)showTime{

    int currentTime = [time.text intValue];

    int new = currentTime +1;

    int secs  = new;
    int mins  = (secs/60) % 60;
    int hours = (mins/60);

    time.text = [NSString stringWithFormat:@"%.2d:%.2d:%.2d",hours, mins, secs];
}
  • 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-22T02:59:37+00:00Added an answer on May 22, 2026 at 2:59 am

    You’re getting 0 from

    int currentTime = [time.text intValue];
    

    because the string that’s in text:

    @"00:00:00"
    

    can’t be converted to an int, so every time the timer fires, you add 1 to 0 and get 1, which you then display. The math would be inaccurate anyways, because minutes and seconds are “base-60″* — you’d need to do the reverse of the math you perform for separating hours/minutes/seconds, in order to get the total seconds again. You could just make currentTime an ivar, and keep the total number of seconds in it.


    *That’s not really what it’s called; I’m sure there’s a specific word for it.

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

Sidebar

Related Questions

I have the following code that won't compile and although there is a way
I have the following bit of legacy C++ code that does not compile: #include
In Python compiled regex patterns have a findall method that does the following: Return
Assume I have created a compiled re: x = re.compile('^\d+$') Is there a way
When I compiled the following code, it shows that y and the beginning of
I have the following code snippet: #ifdef DO_LOG #define log(p) record(p) #else #define log(p)
I have the following code in my user control: <asp:LinqDataSource ID=myLinqDataSource runat=server AutoSort=true ContextTypeName=MyDBContext
I have the following code (compiler: MSVC++ 10): std::vector<float> data; data.push_back(1.0f); data.push_back(1.0f); data.push_back(2.0f); //
i have the following code in c#. I'm using ASP.NET MVC 3. public override
I have some old (~1995) legacy fortran code which is compiled with g77 compiler

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.