nstimer

Invalidating NSTimer

独自空忆成欢 提交于 2019-12-12 19:51:08
问题 I have 4 NSTimers objects in my app , that make requests to a rest URL every few seconds. On clicking of a particular button I want to stop the timer so that it stops polling and on click of another button I want to resume polling. I have tried invalidate for all timers but does not work. NOTE: All timers are in different class and I'm trying to invalidate the timers in another class Any help will be appreciated , thank you. class NotificationViewController:UIViewController { var timer

iphone development: how to create an animation by using NSTimer

柔情痞子 提交于 2019-12-12 18:30:51
问题 In my app I have this code in viewWillAppear. It simply animates random object from top of the screen to the bottom. The problem is I need to detect collision and what I have learnt so far is it is impossible to retrieve the coordinates at any time for an animation. so how can I implement it by using NSTimer? or shall I use NSTimer? I could not figure it out. Any clue will be appreciated. -(void)viewWillAppear:(BOOL)animated { for (int i = 0; i < 100; i++) { p = arc4random_uniform(320)%4+1;

Why does this NSInvocation raise an exception?

Deadly 提交于 2019-12-12 15:46:30
问题 I have a real head-scratcher right now. So, an NSTimer object, an NSMethodSignature object, and an NSInvocation object walk into a bar. Here's the rest of the joke: NSMethodSignature *methodSig = [NSMethodSignature methodSignatureForSelector:@selector(setAlphaValue:)]; NSInvocation *inv = [NSInvocation invocationWithMethodSignature:methodSig]; CGFloat alphaVal = 1.f; [inv setSelector:@selector(setAlphaValue:)]; [inv setTarget:tabViewItem.view]; [inv setArgument:&alphaVal atIndex:2]; NSTimer

NSTimer continue during sleep mode

Deadly 提交于 2019-12-12 14:01:06
问题 I have a timer app which uses a NSTimer to track minutes. How can I keep the timer going, even when the device is put into sleep mode? Thanks! 回答1: Adjust After Wake Notification Scheduled NSTimer instances will halt during sleep. Your application needs to respond to the NSWorkspace's wake notification and adjust its timers. If you do not respond to wake notifications, your timers will resume but without accounting for the time spent asleep. See Apple's technical note QA1340 Registering and

Is there any reason to retain a scheduled NSTimer if you don't need to invalidate it?

折月煮酒 提交于 2019-12-12 13:33:34
问题 I'm going back over some crufty code to tidy it up and I see I've been retaining NSTimers returned from scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: and storing them in a field - then releasing and nulling the field when it fires. In some cases I use the timer to send an invalidate message to it later - but in many cases not. In more recent code I usually just schedule the timer and forget about it. I understand that the constructor method is autoreleasing and the timer is

Releasing an NSTimer iPhone?

做~自己de王妃 提交于 2019-12-12 09:21:05
问题 I have an NSTimer declared in my .h and in the viewDidLoad of the /m I have the code: timer = [NSTimer scheduledTimerWithTimeInterval:kComplexTimer target:self selector:@selector (main) userInfo:nil repeats:YES]; I also have [timer release]; in my dealloc. However when I exit the view and return to it, the timer has not in fact released, it has doubles in speed! How do I solve this & what am I doing wrong??? Thanks 回答1: Nice Answer , but good to check whether the time is nil or not to avoid

Calculate the time between the switches of a View Controller and another View Controller

妖精的绣舞 提交于 2019-12-12 06:35:42
问题 I created my UIView class showing an internal activity indicator. This view informs you that at that time the application is performing an operation. I'm trying to apply this UIView also login in my app but I have a problem ... I would like to be able to calculate the time that the app takes from the moment the user enters his username and password, up to the moment when access to the home screen of the app. In that moment of time I would see my UIView which informs you that at that moment he

NSTimer gets disturbed while scrolling the UITableView in iphone

耗尽温柔 提交于 2019-12-12 06:26:24
问题 I have got a strange and rare problem here. I am using NSTimer event that play sound repeatedly at 100ms. I have UITableView in same class. When i scroll the tableview the timer gets disturbed. I mean the sound which was playing repeatedly becomes irregular while scrolling tableview. This does not happen in simulator. This problem happens while testing on device. (I use iphone3G) 回答1: NSTimer works on the same thread it was invoked. So if you do this on the main thread (where all UI works),

(iphone) start timer from background thread?

人盡茶涼 提交于 2019-12-12 05:39:21
问题 I create a timer with [NSTimer scheduledTimerWithTimerInterval:target:selector:...] from a background thread It seems the timer created from a background thread doesn't call the selector given as the argument. Is there something special I need to run a timer from background thread? Thank you EDIT Here's the sequence performSelectorInBackground: pushViewController from the viewController's init sequence, I alloc a timer with the above method. and the timer selector won't get called. 回答1: You

How to Save NSTimer?

与世无争的帅哥 提交于 2019-12-12 05:27:56
问题 Can anybody say me how to save NSTimer ? I need to display that, at how much time player completed his/her game. please suggest. Thanks. 回答1: you can do like this way.. int currentTime; BOOL isGameOver; - (void)viewWillAppear:(BOOL)animated { isGameOver=FALSE; [self start]; [super viewWillAppear:YES]; } - (IBAction)start{ currentTime = 0;// SET 60 SECODE AS STATICULLY YOU CAN SET YOUR OWN TIME lbl=[[UILabel alloc]init]; //creates and fires timer every second myTimer = [[NSTimer