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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:57:59+00:00 2026-06-03T07:57:59+00:00

A simplified set of methods to demonstrate what’s happening: – (void)timerDidFire { NSLog(@fire); }

  • 0

A simplified set of methods to demonstrate what’s happening:

- (void)timerDidFire {
    NSLog(@"fire");
}

- (void)resetTimer:(NSTimer *)timer {
    if (timer) [timer invalidate]; // timer = nil; here doesn't change anything
    NSLog(@"%@", timer);
    timer = [NSTimer ...Interval:1 ... repeats:YES];
}

- (IBAction)pressButton {
    [self resetTimer:myTimer];
}

Clearing I’m doing something wrong, but what? Why do I get an extra timer with every press?

  • 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-03T07:58:00+00:00Added an answer on June 3, 2026 at 7:58 am

    Each time the resetTimer: method is called you create a new NSTimer instance. Unfortunately after the execution of this method is finished you lost all your references to the new instance because it was assigned to a local variable.
    The timer you create inside the method is not assigned to the myTimer variable. Whatever myTimer is, it is not the new created timer.

    You could dump all those local variables and simply use something like this:

    - (void)resetTimer {
        [myTimer invalidate]; // calls to nil are legal, so no need to check before calling invalidate
        NSLog(@"%@", myTimer);
        myTimer = [NSTimer ...Interval:1 ... repeats:YES];
    }
    
    - (IBAction)pressButton {
        [self resetTimer];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a simplified version of the 3 data sets I have: Set A =
I've recently noticed that when I create private methods that set a few fields
Simplified Table structure: CREATE TABLE IF NOT EXISTS `hpa` ( `id` bigint(15) NOT NULL
Simplified example <td>caption</a> <a id=tt-1>text1</a> <a id=tt-2>text2</a> <td>topics</td> <a id=tt-3>text3</a> <a id=tt-4>text4</a> <a id=tt-5>text5</a>
A simplified version of problem I am experiencing: Here is my HTML form: <form
My (simplified) table consist of an Id int identity(1,1), File varchar(20), FileProcessed bit The
A simplified version of what i'm trying to do is as follows: var indication
I simplified my code for next example. So, please don't be wondered why I'm
Following simplified code snippet: #include <QtGui> int main(int argc, char **argv) { QApplication app(argc,
This is a simplified example to illustrate the question: class A {}; class B

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.