• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTimer access to its -timerFireMethod
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTimer access to its -timerFireMethod


  • Subject: NSTimer access to its -timerFireMethod
  • From: John Love <email@hidden>
  • Date: Wed, 14 Jul 2010 08:06:38 -0400

This is just out of academic curiosity because I can successfully use:  [NSThread detachNewThreadSelector: toTarget: withObject:] to do what I want.  Nevertheless, I have been trying to do the same thing in the main Thread with NSTimer and something is wrong that I just cannot figure out.  So, here are some snippets:

In the .h file I have:   NSTimer *itsTimer;

In the .m file I have:

- (void )startTimer {
	if (!itsTimer || ![itsTimer isValid]) {
		NSTimer *theTimer;
		theTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
		itsTimer = theTimer;
	}
}

- (void )stopTimer {
	if (itsTimer && [itsTimer isValid]) {
		[itsTimer invalidate];
		itsTimer = nil;
	}
}

- (void )timerFireMethod:(NSTimer *)theTimer {
	NSLog(@"we are here");  // just to keep it simple at first
}

I call -startTimer and -stopTimer from the main Thread and the NSLog(@"we are here") never shows in the Console.

I did try, unsuccessfully:
		theTimer = [[NSTimer alloc] initWithFireDate:[NSDate date] interval:0.5 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
		[[NSRunLoop currentRunLoop] addTimer:theTimer forMode:NSDefaultRunLoopMode];
		itsTimer = theTimer

I think I have found the problem, but I would like confirmation ... the calls are from the main Thread, immediately followed by the display of a sheet.  I am trying to intercept errors while the sheet shows.  And while the sheet shows, all access to -timerFireMethod is temporarily halted.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSTimer access to its -timerFireMethod
      • From: Graham Cox <email@hidden>
  • Prev by Date: Live updating user defaults from a prefpane to a running app
  • Next by Date: Re: Adding an image to a project
  • Previous by thread: Re: Live updating user defaults from a prefpane to a running app
  • Next by thread: Re: NSTimer access to its -timerFireMethod
  • Index(es):
    • Date
    • Thread