nstimer

iPhone dev — performSelector:withObject:afterDelay or NSTimer?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 18:12:42
问题 To repeat a method call (or message send, I guess the appropriate term is) every x seconds, is it better to use an NSTimer (NSTimer's scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:) or to have the method recursively call itself at the end (using performSelector:withObject:afterDelay)? The latter doesn't use an object, but maybe its less clear/readable? Also, just to give you an idea of what I'm doing, its just a view with a label which counts down to 12:00 midnight, and when

How do I change timing for NSTimer?

百般思念 提交于 2019-12-04 16:53:35
问题 I have the following code: timer = [[NSTimer scheduledTimerWithTimeInterval:0.50 target:self selector:@selector(onTimer) userInfo:nil repeats:YES] retain]; -(void) onTimer { } After every 0.50 seconds the OnTimer method is called. But now I want to increment the time-interval. That means: OnTimer calls after 0.55 OnTimer calls after 0.60 OnTimer calls after 0.65 OnTimer calls after 0.70 OnTimer calls after 0.75 & so on. Is there any solution for this?? I have tried lot but its not working.

How to trigger NSTimer right away?

二次信任 提交于 2019-12-04 14:58:00
问题 I need to call a method when my app starts and then call the same method every 5 seconds. My code is pretty simple: // Call the method right away [self updatestuff:nil] // Set up a timer so the method is called every 5 seconds timer = [NSTimer scheduledTimerWithTimeInterval: 5 target: self selector: @selector(updatestuff:) userInfo: nil repeats: YES]; Is there an option for the timer so it's trigger right away and then every 5 seconds ? 回答1: NSTimer 's -fire , [timer fire]; is what you're

iPhone: How to code a reducing countdown timer?

前提是你 提交于 2019-12-04 14:09:14
问题 I want to show a countdown timer using a UILabel which will start from 5 and reduces by 1 every second like: 5 4 3 2 1 and finally hides the label when it reaches 0. I tried to code it using NSTimer scheduledTimerWithTimeInterval but failed miserably. Please help me. 回答1: I was just doing something like that. I have a UILabel that is called timeReamin in my code. It's updated every second until it reaches 0 and then an alert is displayed. I must warn you that since the timer runs on the same

How to create an alarm clock app with swift?

你说的曾经没有我的故事 提交于 2019-12-04 14:03:23
I'm trying to create a kind of alarm clock app with the swift but I could not figure out how to set an alarm model. I've tried UILocalnotification but I don't want my users to be involved the flow of alarm app other than setting the alarm. Then tried NSTimer and NSRunloop etc. but that didn't work either since those don't work when app gets background. So is there any alternative ways to do that? Any help and suggestion would be appreciated, thanks. I have been doing research on this for quite some time now. But didn't find any concrete way to do it. You have to use one of the following from

(Swift) NSTimer Stop when Scrolling [duplicate]

被刻印的时光 ゝ 提交于 2019-12-04 13:31:16
问题 This question already has an answer here : NSTimer stops during scrolling (1 answer) Closed 3 years ago . Help me. I tried to make NSTimer with UIScrollView. but NSTimer stop during Scrolling on UIScroll View.. How can I keep work NSTimer during scrolling? 回答1: I created a simple project with a scrollView and a label that is updated with an NSTimer . When creating the timer with scheduledTimerWithInterval , the timer does not run when scrolling. The solution is to create the timer with

How to pause a NSTimer? [duplicate]

偶尔善良 提交于 2019-12-04 13:02:33
问题 This question already has answers here : How can I programmatically pause an NSTimer? (15 answers) Closed 6 years ago . I have a game which uses a timer. I want to make it so the user can select a button and it pauses that timer and when they click that button again, it will unpause that timer. I already have code to the timer, just need some help with the pausing the timer and the dual-action button. Code to timer: -(void)timerDelay { mainInt = 36; timer = [NSTimer

How to stop/invalidate NStimer

白昼怎懂夜的黑 提交于 2019-12-04 11:50:54
问题 I am using [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(update) userInfo:nil repeats:YES]; I want to stop calling this timer one. viewDidDisappear How can i do that? invalidate? 回答1: Declare NSTimer *myTimer in .h file. Assign instance as tom said like this myTimer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(update) userInfo:nil repeats:YES]; Stop and Invalidate using this - (void) viewDidDisappear:(BOOL)animated { [myTimer

NSTimers running in background?

陌路散爱 提交于 2019-12-04 10:36:54
问题 I was under the impression that NSTimer did not work at all after an application calls applicationWillResignActive . I seems however that existing NSTimers (i.e. ones created before the application resigned active) will continue to run and its only new NSTimers that can't be scheduled in this state, can anyone confirm this? I am also assuming that its good (and Apple seems to say this too) that when your application calls applicationWillResignActive you should disable any NSTimers and start

Display StopWatch Timer in UITableViewCell dynamically

假如想象 提交于 2019-12-04 10:15:15
I want to hold timer values and Display it from start in new UITableViewCell but my problem is that I am successfully able to display stopwatch timer on first Cell but when I am trying to add a new cell in UITableView so my timer is set to second cell and I am unable to define how to keep my first timer alive. I thought of managing an Array but I want to call reload TableData everytime, but I think that is bad :( I tried work around as below but I am not figuring out how to show timerValue on previous cell with working stopwatch dynamic from same count and new cell timerValue from start. A