Questions tagged [nstimer]

An Objective C class for creating timer objects.

In Objective C (), you use the NSTimer class to create timer objects or, more simply, timers. A timer waits until a certain time interval has elapsed and then fires, sending a specified message to a target object. For example, you could create an NSTimer object that sends a message to a window, telling it to update itself after a certain time interval.

Timers work in conjunction with run loops. To use a timer effectively, you should be aware of how run loops operate—see NSRunLoop and Threading Programming Guide. Note in particular that run loops retain their timers, so you can release a timer after you have added it to a run loop.

A timer is not a real-time mechanism; it fires only when one of the run loop modes to which the timer has been added is running and able to check if the timer’s firing time has passed. Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds. If a timer’s firing time occurs during a long callout or while the run loop is in a mode that is not monitoring the timer, the timer does not fire until the next time the run loop checks the timer. Therefore, the actual time at which the timer fires potentially can be a significant period of time after the scheduled firing time.

NSTimer is “toll-free bridged” with its Core Foundation () counterpart, CFRunLoopTimerRef. See “Toll-Free Bridging” for more information on toll-free bridging.

Additional examples for the NSTimer object can be found here.

2624 questions
6
votes
2 answers

ViewController.Type does not have a member named

Just a simple task, but I'm in trouble. Trying to make a different way but it fails. How to init NSTimer with declared previously variable? Neither var nor let helps.
Olexiy Pyvovarov
  • 870
  • 2
  • 17
  • 32
6
votes
3 answers

NSTimer doesn't stop with invalidate

I add timer like this tim=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(repeatTim) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:tim forMode:NSDefaultRunLoopMode]; tim it is NSTimer property of my…
Sergey92zp
  • 589
  • 4
  • 22
6
votes
1 answer

ios scheduledTimerWithTimeInterval for amount of time

I want to use scheduledTimerWithTimeInterval to do a periodic task for certain amount of time lets say one hour. but How do I implement on my code. Here is my code: timer = [NSTimer scheduledTimerWithTimeInterval: 0.1 …
HelenaM
  • 1,807
  • 6
  • 30
  • 41
6
votes
1 answer

Using NSTimer to call SetNeedsDisplay in Xamarin for iOS

I have a UIView that takes data (thats changing) from a buffer and plots it. I want the screen udpated at 10Hz. The UIView is called pane, and this is how i'm invoking it inside the ViewController: //create graphics to display data …
reza
  • 1,329
  • 2
  • 22
  • 37
6
votes
3 answers

(NSTimer) creating a Timer Countdown

I am trying to create a simple Countdown Timer so that when a player enters my game the timer begins from 60 down to 0. It seems simple but I am getting confused at how I write this. So far I have created a method within my GameController.m that…
6
votes
2 answers

How to know when to invalidate an `NSTimer`

Here's my issue: I have a model class that has an NSTimer in it that I want the Timer to run for the entire lifespan of the model object. Initiliazation is easy: I just have the following line of code in the init…
Nosrettap
  • 10,940
  • 23
  • 85
  • 140
6
votes
2 answers

Creating a StopWatch in Iphone

I am trying to create a simple stopwatch. I referred to this website ( http://www.apptite.be/tutorial_ios_stopwatch.php) to do this app. When I click the start button, I get -596:-31:-23:-648 and the stopwatch does not run. The code looks…
lakshmen
  • 28,346
  • 66
  • 178
  • 276
6
votes
2 answers

Display a timer for an iOS app that persists between view controllers

I've been trying to get a timer to show at the bottom left corner of my app by using an NSTimer, and making the "elapsed time" show as UILabel on the bottom left corner but it hasn't been working for me. -(void)viewDidLoad { NSTimer *aTimer =…
user1677210
  • 169
  • 1
  • 1
  • 13
6
votes
4 answers

How do I invalidate timer when I don't create NSTimer object

I don't want to create NSTimer object. How do I invalidate timer? I want to invalidate timer in viewWillDisappear. -(void) viewDidLoad { [super viewDidLoad]; [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(onTimer:)…
Voloda2
  • 12,359
  • 18
  • 80
  • 130
6
votes
1 answer

NSTimer and NSRunLoop

My app tracks a user with CLLocationManager. In the delegate call didUpdateToLocation I do all the fun stuff of saving their position. However, I needed a way to test if they had stopped. That away I could stop recording locations and consider their…
random
  • 8,568
  • 12
  • 50
  • 85
6
votes
1 answer

How to monitor MPMoviePlayerController playback progress while not killing a battery?

I have a media player app that is playing music with MPMoviePlayerController. I need to update the UI based on the playback position. The best I can tell, there is no way to actively receive this info from the player with a callback or something,…
Jaanus
  • 17,688
  • 15
  • 65
  • 110
6
votes
3 answers

How do I create an accurate timer event in Objective-C/iOS?

I'm looking to create a countdown timer for SMPTE Timecode (HH:MM:SS:FF) on iOS. Basically, it's just a countdown timer with a resolution of 33.33333ms. I'm not so sure NSTimer is accurate enough to be counted on to fire events to create this timer.…
Michael Brown
  • 1,585
  • 1
  • 22
  • 36
6
votes
2 answers

NSTimer Decrease the time by seconds/milliseconds

I am developing a QuiZ app. It needs a countdown timer, In that I want to start a timer at 75:00.00 (mm:ss.SS) and decrease it to 00:00.00 (mm:ss.SS) by reducing 1 millisecond. I want to display an alert that Time UP! when time reaches to 00:00.00…
SriKanth
  • 459
  • 7
  • 27
5
votes
2 answers

multiple countdown timers inside uitableview

How do I go about this task? Basically, I will have an array of "seconds int" listed inside the UITableView. So how can I assign each "seconds int" to countdown to zero? The possible problems I'm seeing is the timers not being updated when the cell…
Diffy
  • 735
  • 1
  • 15
  • 34
5
votes
2 answers

NSTimer not firing

For the life of me, I cannot figure out why this NSTimer wont fire. here is all of the code that appears relevant (at least to me) - (IBAction)connectClick:(id)sender { if (connected) { NSLog(@"Disconnecting"); [timer…
Adam Schiavone
  • 2,412
  • 3
  • 32
  • 65