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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:35:58+00:00 2026-05-26T00:35:58+00:00

So I have a UIPopover with an NSTimer in it. It has various BOOLS

  • 0

So I have a UIPopover with an NSTimer in it. It has various BOOLS and properties to make other methods happen, but that’s not important right now. What I want to know is, is there any way to release and invalidate the timer when the parent view of the popover has disappeared? I tried class methods to invalidate and release the timer, but they gave me SIGABRT and EXC_BAD_ACCESS warnings. I think it had something to do with the timer being to told to dealloc when it was already nil.

A couple extra factors:
1. The timer must stay valid and alloc’d when the popover is dismissed.
2. The timer must invalidate and dealloc when the parent view has disappeared.

Any suggestions?

CODE:

//@interface
    NSTimer *clickTimer;
@property (nonatomic, retain) NSTimer *clickTimer;

//.m
- (IBAction)clickerPressed:(id)sender
{
if ([click isClicking] == YES) {
    [clickTimer invalidate];
    [clickTimer release];
    clickTimer = nil;
    // enable the idle timer when the clicking is turned off
    [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
    [click setIsClicking:NO];
    [clickerButton setBackgroundImage:[UIImage imageNamed:@"wood.png"] forState:UIControlStateNormal];
    [clickerButton setTitle:@"Start" forState:UIControlStateNormal];
    [clickStatus setText:[NSString stringWithFormat:@"%d",[click numberOfBeatsToDisplay]]];
    [click setClickCount:0];

} 
else {
    // disable the idle timer while the metronome is clicking.
    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
    [click setIsClicking:YES];
    [clickerButton setBackgroundImage:[UIImage imageNamed:@"wood.png"] forState:UIControlStateNormal];
    [clickerButton setTitle:@"Stop" forState:UIControlStateNormal];
    [[NSThread currentThread] setThreadPriority:1.0];

    clickTimer = [[NSTimer scheduledTimerWithTimeInterval:[click clickRateInSeconds] target:self selector:@selector(click:) userInfo:nil repeats:YES]retain];
    }

}

  • 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-26T00:35:58+00:00Added an answer on May 26, 2026 at 12:35 am

    Releasing an object does not automatically assign nil to the pointer. Add clickTimer = nil; after your release statement. This will prevent another method from accessing an invalid object if it attempts to release clickTimer.

    To ensure that all of your methods properly set the clickTimer to nil, you might consider creating a method that invalidates the timer for you rather than having each method invalidate the timer:

    - (void) invalidateClickTimer
    {
        // invalidate timer
        if (clickTimer == nil)
            return;
        [clickTimer invalidate];
        [clickTimer release];
        clickTimer = nil;
    
        // stop clicking
        [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
        [click setIsClicking:NO];
        [clickerButton setBackgroundImage:[UIImage imageNamed:@"wood.png"] forState:UIControlStateNormal];
        [clickerButton setTitle:@"Start" forState:UIControlStateNormal];
        [clickStatus setText:[NSString stringWithFormat:@"%d",[click numberOfBeatsToDisplay]]];
        [click setClickCount:0];
        return;
    }
    

    Then replace the following lines in - (IBAction)clickerPressed:(id)sender

    if ([click isClicking] == YES) {
        [clickTimer invalidate];
        [clickTimer release];
        clickTimer = nil;
        // enable the idle timer when the clicking is turned off
        [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
        [click setIsClicking:NO];
        [clickerButton setBackgroundImage:[UIImage imageNamed:@"wood.png"] forState:UIControlStateNormal];
        [clickerButton setTitle:@"Start" forState:UIControlStateNormal];
        [clickStatus setText:[NSString stringWithFormat:@"%d",[click numberOfBeatsToDisplay]]];
        [click setClickCount:0];
    }
    

    With this line:

    if ([click isClicking] == YES) {
        [self invalidateClickTimer];
    }
    

    Call the new method - (void) invalidateClickTimer from the parent view’s UIViewController. Probably in the method - (void)viewWillDisappear:(BOOL)animated

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

Sidebar

Related Questions

Have a matrix report now that has Position, Hours and Wages for a location
have not tested on windows. but in ubuntu when u disconnect from the network,
I have an iPad app that I would like to make Universal, however this
I have a UIPopover that I want to use either -(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{ return NO;
I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in
I have the following view controller in my UIPopover: @protocol StorePopoverDelegate - (void)storeSelected:(NSString *)store;
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =
Have converted devise new session from erb to Haml but doens't work, this is
Have searched the database but need to specifically sum(of hours flown or days off)in
Is it possible to have the keyboard show inside a UIPopOver instead of filling

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.