nstimer

Update Text Label From Another View

戏子无情 提交于 2020-01-17 16:37:10
问题 I have an NSTimer that runs every 10 seconds and is kicked off from LandingController.m. It continues to run as you go to other views in the application. I want to be able to (when a certain condition is met within that timer) update a label field from another view GuardMenu.m The label I want to update is called CurrentZone.text and I want to update it from value "N" to value "Y." Here's my timer on LandingController.m self.messageTimer = [NSTimer scheduledTimerWithTimeInterval:10.0 target

no delay achieved with NSTimer

我只是一个虾纸丫 提交于 2020-01-17 15:29:13
问题 I want to delay between each output result for say, 1 second. The code below is not delaying but is processing correctly. Why is it not delaying between each dealCard ? - (IBAction)startPause { if ([self.deal length]>cardNum) { timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(dealCard) userInfo:nil repeats:NO]; [timer fire]; } } - (void) dealCard{ card.text = [NSString stringWithFormat:@"%i",cardNum+1]; cardTo.text = [self.deal substringWithRange:(NSRange){(cardNum

no delay achieved with NSTimer

拥有回忆 提交于 2020-01-17 15:27:39
问题 I want to delay between each output result for say, 1 second. The code below is not delaying but is processing correctly. Why is it not delaying between each dealCard ? - (IBAction)startPause { if ([self.deal length]>cardNum) { timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(dealCard) userInfo:nil repeats:NO]; [timer fire]; } } - (void) dealCard{ card.text = [NSString stringWithFormat:@"%i",cardNum+1]; cardTo.text = [self.deal substringWithRange:(NSRange){(cardNum

NSTime create a timeInterval

倖福魔咒の 提交于 2020-01-14 06:43:42
问题 I have the following code in my application in the method updateLabel2 : timeLeft = [[NSDate date] timeIntervalSinceDate:[[NSUserDefaults standardUserDefaults] objectForKey:@"lastDate"]]; [[self timer] setText:[NSString stringWithFormat:@"Time Remaining: %f", timeLeft]]; //Set the label text Note that timer is a label. and earlier, the following code is executed: [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:@"lastDate"]; self.repeatTimer = [NSTimer

How to invoke a method daily at a specific time in iPhone application?

喜你入骨 提交于 2020-01-13 13:13:55
问题 I want to invoke a method daily at a specific time in my iPhone application. How can I achieve this? 回答1: There's not a whole lot you can do with the iPhone SDK and a closed app. You can have it send local push notifications at specific times, but that won't execute your code until the user manually opens your app. See this related question recently asked: Is it possible to have my closed app run code in iOS? One thing I've seen apps do (like alarm clock apps, etc) is have you leave your app

Swift Progress View with NSTimer

孤街浪徒 提交于 2020-01-13 06:43:09
问题 I have a Progress view bar that I would like to use to indicate time. This is my first project in Swift, and I am unsure how to go about this. So any help/ advise would be appreciated ... (Using Xcode 7.2 and Swift 2.0) Below Is my view controller. When 'btnPlaySession' is triggered, the content on the view controller is changed every 20 seconds. While the timer is counting to 20, id like to indicate this with the progress bar (so the progress bar resets, each time the content changes). class

NSTimer Accuracy

痴心易碎 提交于 2020-01-11 06:48:10
问题 I am currently working on an app that requires a sound file to be played at exact intervals, which are variable in duration. I seem to remember being told that NSTimer simply places an operation onto the stack after the specified duration, rather than the operation being run after the specified duration. This would mean that if there were lots of other operations on the stack before it, it would not be called on time. I would like to know if this is indeed correct, and if so, is there any way

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

旧巷老猫 提交于 2020-01-08 11:36:48
问题 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? 回答1: 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

Reset NSTimer after navigating to another view

淺唱寂寞╮ 提交于 2020-01-07 05:41:27
问题 Currently I am developing a game which needs a stop watch say 1 minute,when user taps the play button it enters the game screen,I want the to run the stop watch count down of 1 minute 01:00,00:59,00:58 etc. For that reason I searched and found NSTimer would be the ideal choice to implement a stop watch.Hence I took a label,created an instance of NSTimer,assigned time interval and started decrementing the value in timer label,i.e.: -(void)viewDidAppear:(BOOL)animated { self.stopWatchTimer =

How to loop NSTimer in SWIFT with a specific number of counting

孤者浪人 提交于 2020-01-06 14:09:48
问题 I am trying to loop a timer with a specific number of counting... eg... 1, 2, 3, 4, 5 then loop again, the same counting, 10 times, then stop. I was able to do the counting, but I can't do the looping of the counting. What am I doing wrong? var times = 0 var stopCounting = 10 @IBAction func buttonPressed(sender: UIButton) { self.startTimer() } func startTimer(){ self.timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("startCounting"), userInfo: nil, repeats: