nstimer

NSTimer not firing

蓝咒 提交于 2019-11-30 05:59:53
问题 I have an NSTimer that I init with this code: testTimer = [[NSTimer alloc] initWithFireDate:[new objectAtIndex:0] interval:0.0 target:self selector:@selector(works:) userInfo:nil repeats:NO]; [new objectAtIndex:0] is an NSDate in the past. When I start up the app, the timer is getting created, with a fireDate of immediately (since the date is in the past), however it never calls my works method. ( -(void)works:(id)sender ) Anybody know why this is happening? 回答1: You will have to add it to

Swift Solid Metronome System

喜夏-厌秋 提交于 2019-11-30 05:26:11
I am trying to build a reliable solid system to build a metronome in my app using SWIFT. I Have built what seems to be a solid system using NSTimer so far.. The only issue I am having right now is when the timer starts the first 2 clicks are off time but then it catches into a solid timeframe. Now after all my research I have seen people mention you should use other Audio tools not relying on NSTimer.. Or if you choose use NSTimer then it should be on its own thread. Now I see many confused by this Including myself and I would love to get down to the bottom of this Metronome business and get

NSTimer requiring me to add it to a runloop

ぐ巨炮叔叔 提交于 2019-11-30 03:15:20
I am wondering if someone can explain why dispatching back to the main queue and creating a repeating NSTimer I am having to add it to RUN LOOP for it too fire? Even when using performselectorOnMainThread I still have to add it to a RUN LOOP to get it to fire. Below is an example of my question: #define queue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) #define mainqueue dispatch_get_main_queue() - (void)someMethodBeginCalled { dispatch_async(queue, ^{ int x = 0; dispatch_async(mainqueue, ^(void){ if([_delegate respondsToSelector:@selector(complete:)]) [_delegate complete:nil]

NSTimer crashes, when I call [Timer isValid] or [Timer invalidate]

不羁的心 提交于 2019-11-30 02:47:27
问题 I have two NSTimers in my iPhone app. DecreaseTimer works fine, but TimerCountSeconds crashes when I call [timerCountSeconds isValid] or [timerCountSeconds invalidate]. They are used like this: -(id)initialize { //Gets called, when the app launches and when a UIButton is pressed if ([timerCountSeconds isValid]) { [timerCountSeconds invalidate]; } } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //Gets called, when you begin touching the screen //.... if ([decreaseTimer

how to show countdown on uilabel in iphone?

久未见 提交于 2019-11-30 02:22:34
i have a uilabel and a uislider on a view. i want to set label's time using slider.range of slider is 00:00:00 to 03:00:00. means 3 hours.and intervel on slider is 0.5 minutes.also how to show.i want the timer runs even if application is closed. First off, there's no way to keep the timer running after your app is closed. Background apps simply aren't allowed on the iPhone. There are ways to fake it with a timer (save a timestamp when the app exits, and check it against the time when it starts back up), but it won't handle the case where your timer runs out before the app is started back up.

Difference in scheduling NSTimer in main thread and background thread?

风流意气都作罢 提交于 2019-11-30 01:21:11
When I call scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: on the main thread and set time interval to 5 seconds code below timer gets executed, and after 5 seconds timer selector is called. But if I try same in some background thread, the code below scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: will not be executed, it will wait for the timer to fire and then gets executed. Of course, in order to run the timer in the background thread, I first got an instance of NSRunLoop and run it. Is there a way to set the timer in the background thread and make it non

NSTimer with anonymous function / block?

牧云@^-^@ 提交于 2019-11-30 01:14:38
I want to be able to schedule three small events in the future without having to write a function for each. How can I do this using NSTimer ? I understand blocks facilitate anonymous functions but can they be used within NSTimer and if so, how? [NSTimer scheduledTimerWithTimeInterval:gameInterval target:self selector:@selector(/* I simply want to update a label here */) userInfo:nil repeats:NO]; You can actually call: NSTimer.scheduledTimerWithTimeInterval(ti: NSTimeInterval, target: AnyObject, selector: #Selector, userInfo: AnyObject?, repeats: Bool) Use it like this: NSTimer

How to call a method every x seconds in Objective-C using NSTimer?

瘦欲@ 提交于 2019-11-30 00:06:54
I am using Objective-C, Xcode 4.5.1 and working on an app for the iPhone. I have a method A in which I want to call another method B to do a series of calculations every x seconds. In method A I start playing an audio file. Method B will monitor the audio every x seconds for the duration of the audio file. I have found NSTimer as a potential solution, but am having a hard time getting it to work/understanding it. I simply want to call Method B every x seconds and run its calculations, but NSTimer requires me to provide several things of which I'm not sure what I'm supposed to tell it. [NSTimer

NSTimer stops during scrolling

杀马特。学长 韩版系。学妹 提交于 2019-11-29 23:50:44
问题 During debugging my IOS project developed in XCode4 , I initialize and run an NSTimer object. However, the timer stops as soon as I press the scroll view and it continues to run after I release the scroll. Is there a configuration for NSTimer such that timer is not blocked during scrolling? Thanks in advance. 回答1: Add this single line and try again please [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; 来源: https://stackoverflow.com/questions/17423900/nstimer-stops

Countdown with several decimal slots, using NSTimer in Swift

点点圈 提交于 2019-11-29 23:16:57
问题 I want to make an app that has a timer starting at 10.0000000 for example, and I want it to countdown perfectly Here's my code so far: import UIKit class ViewController: UIViewController { @IBOutlet weak var labelTime: UILabel! var counter = 10.0000000 var labelValue: Double { get { return NSNumberFormatter().numberFromString(labelTime.text!)!.doubleValue } set { labelTime.text = "\(newValue)" } } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the