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
0
votes
1 answer

Is it possible to run a scheduled timer in a suspended app?

I've read several posts on creating a timer that runs in the background. Is it possible to create a scheduled timer that will continue to run once the app has been suspended/terminated? Apple's own timer achieves this, but it's not clear how. I am…
user1162328
0
votes
3 answers

Countdown timer using NSTimer in "0:00" format

I have been researching for days on how to do this and nobody has an answer. I am creating an app with 5 timers on the same view. I need to create a timer that counts down from "15:00" (minutes and seconds), and, another that counts down from "2:58"…
0
votes
3 answers

Will subview UIView get any callback when the containing UIViewController viewWillDisappear gets called

I have a custom control which i have added to view of UIViewController, it has a timer in it and my requirement is to stop the timer when ViewController disappears(ie let us say new ViewController gets pushed on the stack). Right now i am manually…
Kishoretheju
  • 827
  • 3
  • 8
  • 18
0
votes
1 answer

Application did enter background function

Hey I got a pretty low interval timer in my firstViewController which I would like to terminate when the app enters background, but how am I supposed to access it from my Applications AppDelegate file where the function is located. I know this is…
Samuli Lehtonen
  • 3,840
  • 5
  • 39
  • 49
0
votes
1 answer

Does not implement methodSignatureForSelector and unrecognized selector when using Timer

Here I have a simple class that prints "test" several times a second: import Foundation class TestClass { static var count = 0 static var timer = Timer() init() { TestClass.start() } static func start() { …
akmin04
  • 677
  • 6
  • 14
0
votes
1 answer

Xamarin iOS: Starting timer crashes app with no exception

I'm developing a Xamarin Forms app for which I needed to write some code native, I got the code working in Android, but I can't get it to work for iOS. In Main.cs I start a scheduled timer with NSTimer which, when finished should start up the…
Dennis van Opstal
  • 1,294
  • 1
  • 22
  • 44
0
votes
2 answers

App crashes after the timer Instead of re-enabling button

I am new to XCode so any help will be appreciated. On button press, the button should be disabled and should display a random number and trigger a timer. Once the timer is is done then the button is enabled again. Here is the button code: @IBAction…
sillyJohn
  • 5
  • 4
0
votes
1 answer

Trying to reuse a timer for cellForRowAtIndexPath

So my goal is to re-use a timer for every cell. Every thing is working fine except one fine point. The cell.indexpath.row start at 1 instead of 0. And even when I scroll to the top, and it bounces back, it goes to 1. The problem with this is that…
bradford gray
  • 537
  • 2
  • 5
  • 18
0
votes
1 answer

timer pause button reseting when press start again

So I have a program which is a stopwatch and I have the stopwatch is working but when I press the pause button the thing pauses but when I press the start button again to start the stopwatch from where it left off it resets instead I have tried…
Bhavin p
  • 98
  • 10
0
votes
1 answer

Using Timer To Schedule Notifications Triggering

I am trying to schedule a Timer to fire at a specific date and time, based on what the user selects in UIDatePicker. When the Timer fires, I want to set up a repeating notification (UNTimeIntervalNotificationTrigger) every 60 seconds. The Timer…
user7531085
0
votes
0 answers

NSTimer slowing down and pausing when minimized

I've searched endlessly for this answer and am surprised I haven't found anything (yet). What I have is an app with a super simple timer function; start the clock timer, and seconds start to click up. If the app is in the foreground, the timer…
Drew
  • 1,422
  • 1
  • 18
  • 29
0
votes
2 answers

How to have a delay in seconds on timer app?

I am attempting to create a time app that is for the time that is a little off, such as I want a second in the app that is actually 1.5 seconds in real time. Currently, I am running into errors on changing the time label and have no idea where to…
Amber
  • 5
  • 2
0
votes
1 answer

Alternative to using CABasicAnimation callbacks?

CAAnimation does not provide a mechanism for assigning callback functions other than the standard "animationDidStart:"/"animationDidStop:" methods. I have a custom UIControl that utilizes 2 CALayers that overlap. The purpose of this control is…
quickthyme
  • 1,250
  • 1
  • 13
  • 16
0
votes
6 answers

Stop NSTimer when float is 0

I've got a NSTimer and a label which shows the seconds counting down. -(void)start { myTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(showActivity) userInfo:nil repeats:YES]; } -(IBAction)stop { [myTimer…
Leon
  • 417
  • 3
  • 11
  • 24
0
votes
1 answer

Mock Animation running out of memory

I am trying to simulated animation based on a series of 54 images. I am getting an - "Program received signal: “0”." message - running out of memory. I am trying my best to take care of them by I seem to be failing. I am running through all 54 in…
smcdrc
  • 1,671
  • 2
  • 21
  • 29