nstimer

Invalidating an NSTimer?

泄露秘密 提交于 2019-12-24 14:57:20
问题 If I have an NSTimer that starts in viewdidload, where is the proper place to invalidate it when leaving that view? Is it also necessary to release it as well? 回答1: If you create a timer with NSTimer scheduledTimerWithTimeInterval... then you don't need to release it, as you don't own it. Now important thing is that the timer class retains the target, and in most cases we use self as the target. If the timer is not repetitive , then after the timer handler is completed, it automatically

Replace usleep with NSTimer?

不羁的心 提交于 2019-12-24 14:22:12
问题 How can I substitute usleep with NSTimer in the following code: /** * DETERMINATE BAR with LABEL */ - (void)showDeterminateBarWithLabel:(CDVInvokedUrlCommand *)command { // obtain commands bool dim = [[command.arguments objectAtIndex:0] boolValue]; int increment = [[command.arguments objectAtIndex:1] intValue]; NSNumber* incrementValue = @(increment); NSString* text = [command.arguments objectAtIndex:2]; // initialize indicator with options, text, detail self.progressIndicator = nil; self

Implementing NSTimer into Code - Swift

早过忘川 提交于 2019-12-24 13:25:51
问题 I am having a bit of trouble using / implementing NSTimer into code. So far, i have this: //Delay function from http://stackoverflow.com/questions/24034544/dispatch-after-gcd-in-swift/24318861#24318861 func delay(delay:Double, closure:()->()) { dispatch_after( //adds block for execution at a specific time dispatch_time( //creates a dispatch time relative to default clock DISPATCH_TIME_NOW, //Indicates that something needs to happen imediately Int64(delay * Double(NSEC_PER_SEC)) //a 64bit

NSTimer你真的会用了吗

淺唱寂寞╮ 提交于 2019-12-24 08:56:08
NSTimer你真的会用了吗    看到这个标题,你可能会想NSTimer不就是计时器吗,谁不会用,不就是一个能够定时的完成任务的东西吗?   我想说你知道NSTimer会retain你添加调用方法的对象吗?你知道NSTimer是要加到runloop中才会起作用吗?你知道NSTimer会并不是准确的按照你指定的时间触发的吗?你知道NSTimer就算添加到runloop了也不一定会按照你想象中的那样执行吗?   如果上面提出的哪些问题,你并不全部了解,那么请细心的看完下面的文章,上面的那几个问题我会一一说明,并给出详细的例子。 一、什么是NSTimer    官方给出解释是“A timer provides a way to perform a delayed action or a periodic action. The timer waits until a certain time interval has elapsed and then fires, sending a specified message to a specified object. ” 翻译过来就是timer就是一个能在从现在开始的后面的某一个时刻或者周期性的执行我们指定的方法的对象。 二、NSTimer和它调用的函数对象间到底发生了什么   

How to implment laps in Stop Watch iphone app

拟墨画扇 提交于 2019-12-23 18:50:08
问题 I am building one application which has stop watch as its accessory function. I am trying to do something very similar to iOS stop watch. I got stop, reset functionality working but I could not get start (once it stop and user click on start) and lap functions working properly. I tried to look around for this problem but I could not find anything besides one time start and reset stop watch tutorials.Here is what I have right now. Can anyone help me out here with this functions ? // Stop Watch

NSTimer causes “unrecognized selector” crash when it fires

被刻印的时光 ゝ 提交于 2019-12-23 18:21:04
问题 I'm using a NSTimer to run an animation (for now just call it myMethod ). However, its causing a crash. Here's the code: @implementation SecondViewController // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void) myMethod { NSLog(@"Mark Timer Fire"); } - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"We've loaded scan"); [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(myMethod:) userInfo:nil repeats:YES];

Swift countdown timer labels for Days/Hours/Minutes/Seconds

风格不统一 提交于 2019-12-23 10:39:38
问题 I'm creating a countdown timer that counts down to an NSDate set in a UIDatePicker . I have a label that shows the date we're counting down to and that works fine. What I'm also trying to add is labels for the number of whole days left and number of hours/minutes/seconds left in the current day (i.e. never more than 23/59/59) Here's what I've done at the minute but it obviously shows the values for the whole countdown. Hoping someone can help me work out the correct logic here. let

ios scheduledTimerWithTimeInterval for amount of time

耗尽温柔 提交于 2019-12-23 09:07:14
问题 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 target: self selector: @selector(doSomething:) userInfo: nil repeats: YES]; 回答1: Lets assume for a minute . Here is simple scenario , int remainingCounts; NSTimer *timer; timer = [NSTimer scheduledTimerWithTimeInterval:1 target:(self) selector:@selector(countDown) userInfo:nil

NSTimer events do no occur when screen locked on iOS 5

寵の児 提交于 2019-12-23 05:45:06
问题 I've seen this come up a few times but I haven't really seen a definite answer... Since iOS 5 my application seems to run into the problem that if the user locks the screen my NSTimer stops firing after about 20 seconds in the lock screen. This makes my app which plays a sound every time the timer fires pointless if the user locks the screen. This has only happened since I updated my device to iOS 5. My question is that 1. Is there any workaround to having this same functionality work on

How to add time to a countdown timer to iOS Project

£可爱£侵袭症+ 提交于 2019-12-23 05:02:21
问题 I have a game where is uses a countdown timer and when the timer is up, you are brougt to a Game over view. I want to add a feature were if they tap a button, it will add like 1, 2 or 3 more seconds to the timer. I already have the code for the timer (Below), but i just need to know how to add more time to the counter. I thought of it and i have to say when the views will switch and it would need to take into a count the added time. Code: -(IBAction)Ready:(id)sender { [self performSelector: