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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:03:08+00:00 2026-05-25T18:03:08+00:00

Once a IBAction is pressed, I want a counter which counts up. But in

  • 0

Once a IBAction is pressed, I want a counter which counts up.

But in this form

00:00:00
Hours:minutes:seconds

This is the code so far:

-(void)countUp {

    mainInt += 1;
    seconds.text = [NSString stringWithFormat:@"%02d", mainInt];

}

This only counts up in 00 format

Thanks for the help!

  • 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-25T18:03:09+00:00Added an answer on May 25, 2026 at 6:03 pm

    Just do the appropriate math to break the count up into its constituent parts:

    NSString *timeString = [NSString stringWithFormat:@"%02d:%02d:%02d",
                                                      totalSeconds/3600,        // hours
                                                      (totalSeconds/60)%60,     // minutes
                                                      totalSeconds%3600]        // seconds
    

    For the sake of readability, it’d be nice to replace that inline math with macros or functions, for example:

    #define secondsPerMinute 60
    #define minutesPerHour 60
    
    int hours(int secs) {
        return secs/(minutesPerHour * secondsPerMinute);
    }
    
    int minutes(int secs) {
        return (secs/secondsPerMinute) % minutesPerHour;
    }
    
    int seconds(int secs) {
        return secs % (minutesPerHour * secondsPerMinute);
    }
    
    // ...
    NSString *timeString = [NSString stringWithFormat:@"%02d:%02d:%02d",
                                                      hours(totalSeconds),
                                                      minutes(totalSeconds),
                                                      seconds(totalSeconds)];
    

    Often when implementing this sort of display, you don’t want the colons to jump around as the elapsed time changes. Many fonts have fixed-width numerals, so it’s not always a problem, but you might want to use three separate labels for the hours, minutes, and seconds, with unchanging labels in between for the colons.

    Another approach to the math above is to store the seconds, minutes, and hours in three variables instead of one, and just be careful to increment minutes and reset seconds when seconds hit 60, and so on. To make this easier to use, encapsulate it in a class, like:

    @interface Time : NSObject {
        int seconds;
        int minutes;
        int hours;
    }
    - (void)countUp;
    - (NSString*)timeString;
    @end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code to open a popover with imagepicker -(IBAction)photosAction:(id)sender { //
I have been looking at this for hours but can't find out what's wrong.
So, I have a form (which is basically a UITableView), and once I finish
Once again, I'm at a loss with IE7 on this one. I'm making a
I need with one button to change text color, but not once, i need
I know this might sound that it should be trivial but I am finding
I'm making this app with a tableview and stuff. I want to make a
I have code setting up a UIAlertView: -(IBAction)showMessage { //NSInteger *buttonIndex = NULL; UIAlertView
I have added following piece of code in a view. - (IBAction)accept_clicked:(id)sender { [self.view
The code is shown as below, I have a button once you click it

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.