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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:26:59+00:00 2026-06-11T16:26:59+00:00

Ok i want to create MULTIPLE timers that all start at a different time

  • 0

Ok i want to create MULTIPLE timers that all start at a different time (25, 50,1 min, 1min 30s…) but i dont know how to make it stop when it reaches 0 and when it does reach zero, bring the “Player” to another view.

Heres my .h file

@interface ViewController :UIViewController {

IBOutlet UILabel *seconds;

NSTimer *timer;

int MainInt;
}

@end

And heres my .m file

@implementation ViewController

-(void)countDownDuration {

MainInt -= 1;

seconds.text = [NSString stringWithFormat:@"%i", MainInt];

}

-(IBAction)start:(id)sender {

MainInt = 25;

timer = [NSTimer scheduledTimerWithTimeInterval:1.0

                                         target:self
                                       selector:@selector(countDownDuration)
                                       userInfo:nil
                                        repeats:YES];
}

@end
  • 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-11T16:27:00+00:00Added an answer on June 11, 2026 at 4:27 pm

    NSTimer doesn’t do this automatically, but it’s trivial to add it to your countDownDuration method. For example:

    -(void)countDownDuration {
      MainInt -= 1;
      seconds.text = [NSString stringWithFormat:@"%i", MainInt];
      if (MainInt <= 0) {
        [timer invalidate];
        [self bringThePlayerToAnotherView];
      }
    }
    

    Of course you want to create multiple timers. You could store each one in a different variable and give each one a different selector. But if you look at the documentation for NSTimer, the callback method actually takes the timer object as a selector; you’re ignoring it, but you shouldn’t be.

    And meanwhile, you can store an object of any type you want as the userInfo for the timer, so that’s a good place to stash a separate current countdown value for each timer.

    So, you can do something like this:

    -(void)countDownDuration:(NSTimer *)timer {
      int countdown = [[timer userInfo] reduceCountdown];
      seconds.text = [NSString stringWithFormat:@"%i", countdown];
      if (countdown <= 0) {
        [timer invalidate];
        [self bringThePlayerToAnotherView];
      }
    }
    
    -(IBAction)start:(id)sender {
      id userInfo = [[MyCountdownClass alloc] initWithCountdown:25];
      timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                               target:self
                                             selector:@selector(countDownDuration:)
                                             userInfo:userInfo
                                              repeats:YES];
    }
    

    I’ve left a few details unwritten (like the definition of MyCountdownClass—which has to include method initWithCountdown: and reduceCountdown that do the right thing), but they should all be pretty simple. (Also, presumably you want a userInfo that stores more than just the countdown value—e.g., if each timer sends the player to a different view, you’ve got to stash the view there as well.)

    PS, notice that you now need @selector(countDownDuration:). Newcomers to ObjC screw this up all the time. countDownDuration: and countDownDuration are completely unrelated selectors.

    PPS, the full definition of MyCountdownClass will have to be visible in countDownDuration: (unless you have some other class with the same selectors). You may want to explicitly cast the result of userInfo to MyCountdownClass * to make things clearer.

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

Sidebar

Related Questions

I want to create an array that has multiple index and in each index
I want to create a UI that uses a tab control to display multiple
i want create multiple search where statement $where_search is a multiple condition from post
I want to create multiple versions of print-friendly pages from a single page. I
I`v come across a need where I want to create multiple list items from
I have an XML file (on the left) and I want to create multiple
hey i want to be able to create multiple shapes and store them perhaps
I want to create a single video file from multiple video files (parts). I
I want my code to automatically try multiple ways to create a database connection.
I wanna create a public repo (bare repo) which contains multiple submodules. I want

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.