nstimer

NSTimer not firing when runloop is blocked

允我心安 提交于 2019-11-26 15:48:33
问题 I am just about finished with my app and beta testing found a bug in the stopwatch portion... The stopwatch uses an nstimer to do the counting and has a table for storing laps, but when the lap table is scrolled the watch stops or pauses and does not make up for the lost time. This was stalling was eliminated by using: startingTime = [[NSDate date] timeIntervalSince1970]; to calculate the elapsed time. but I am still using the NSTimer to trigger every 0.1 secs and that means that the

How to detect a pause in input for UISearchBar/UITextField?

£可爱£侵袭症+ 提交于 2019-11-26 13:08:38
问题 I have the following UISearchbar code: - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; NSString* endpoint =[NSString stringWithFormat:@\"http://www.someurl/\", [searchText stringByReplacingOccurrencesOfString:@\" \" withString:@\"+\"]]; NSURL* url = [NSURL URLWithString:endpoint]; NSURLRequest* request = [NSURLRequest requestWithURL:url]; GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher

Scheduled NSTimer when app is in background?

允我心安 提交于 2019-11-26 12:51:18
How do people deal with a scheduled NSTimer when an app is in the background? Let's say I update something in my app every hour. updateTimer = [NSTimer scheduledTimerWithTimeInterval:60.0*60.0 target:self selector:@selector(updateStuff) userInfo:nil repeats:YES]; When in the background, this timer obviously doesn't fire(?). What should happen when the user comes back to the app..? Is the timer still running, with the same times? And what would would happen if the user comes back in over an hour. Will it trigger for all the times that it missed, or will it wait till the next update time? What I

Passing parameters to a method called by NSTimer in Swift

大城市里の小女人 提交于 2019-11-26 12:33:40
问题 I\'m trying to pass an argument to a method that is called by NSTimer in my code. It is throwing an exception. This is how I\'m doing it. Circle is my custom class. var circle = Circle() var timer = NSTimer.scheduledTimerWithInterval(1.0, target: self, selector: animate, userInfo: circle, repeats: true) Below is the method that is being called func animate(circle: Circle) -> Void{ //do stuff with circle } Note: The method is in the same class that it is being called. So I believe i\'ve set

How to Pause/Play NSTimer?

狂风中的少年 提交于 2019-11-26 12:27:56
I need to start NSTimer by 0:0:0 that I am doing and I have a Pause button on click of that the timer has to pause after some time if a user clicks play it has to run from paused value of time. How can I pause and play in NSTimer? Any help? Thanks in advance. Try this shizzle... worked great for me EDIT To be honest my actual code is this: -(IBAction)clicked:(id)sender { if ([startStop.titleLabel.text isEqualToString:@"Start"]) { [startStop setTitle:@"Pause" forState:UIControlStateNormal]; [startStop setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; timer = [NSTimer

What's the best way to detect when the app is entering the background for my view?

故事扮演 提交于 2019-11-26 12:12:29
I have a view controller that uses an NSTimer to execute some code. What's the best way to detect when the app is going to the background so I can pause the timer? You can have any class interested in when the app goes into the background receive notifications. This is a good alternative to coupling these classes with the AppDelegate. When initializing said classes: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector

UIScrollView pauses NSTimer until scrolling finishes

此生再无相见时 提交于 2019-11-26 11:15:13
While a UIScrollView (or a derived class thereof) is scrolling, it seems like all the NSTimers that are running get paused until the scroll is finished. Is there a way to get around this? Threads? A priority setting? Anything? An easy & simple to implement solution is to do: NSTimer *timer = [NSTimer timerWithTimeInterval:... target:... selector:.... userInfo:... repeats:...]; [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; For anyone using Swift 3 timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: aSelector, userInfo: nil, repeats: true) RunLoop

Add a running countup display timer to an iOS app, like the Clock stopwatch?

岁酱吖の 提交于 2019-11-26 11:11:24
问题 I\'m working with an app that processes device motion events and updates interface in 5 second increments. I would like to add an indicator to the app that would display the total time the app has been running. It seems that a stopwatch-like counter, like the native iOS Clock app is a reasonable way to count time that the app has been running and display it to the user. What I\'m not sure of is the technical implementation of such a stopwatch. Here\'s what I\'m thinking: if I know how long

How to run a method every X seconds

不问归期 提交于 2019-11-26 10:19:32
I'm developing an Android 2.3.3 application and I need to run a method every X seconds . In iOS, I have NSTimer , but in Android I don't know what to use. Someone have recommend me Handler ; another recommend me AlarmManager but I don't know which method fits better with NSTimer . This is the code I want to implement in Android: timer2 = [ NSTimer scheduledTimerWithTimeInterval:(1.0f/20.0f) target:self selector:@selector(loopTask) userInfo:nil repeats:YES ]; timer1 = [ NSTimer scheduledTimerWithTimeInterval:(1.0f/4.0f) target:self selector:@selector(isFree) userInfo:nil repeats:YES ]; I need

NSTimer

守給你的承諾、 提交于 2019-11-26 10:14:56
NSTimer是Cocoa中比较常用的定时器类,基本操作如下: handleTimer方法可以自行定义。在需要的地方创建timer即可,handleTimer就可以每0.5秒执行一次。 - (void) handleTimer: (NSTimer *) timer { //在这里进行处理 } NSTimer *timer; timer = [NSTimer scheduledTimerWithTimeInterval: 0.5 target: self selector: @selector(handleTimer:) userInfo: nil repeats: YES]; 转载于:https://www.cnblogs.com/mac_arthur/archive/2010/04/09/1708328.html 来源: https://blog.csdn.net/weixin_30239339/article/details/98782253