nstimer

How to display an NSArray in a UILabel and use timer

好久不见. 提交于 2019-12-12 04:44:21
问题 I'm trying to display an array of numbers in a UILabel using a timer,and show them in the order set in the array, but I only receive the Title in the format and then a SIGABRT ! any suggestions...Thanks Part of the code with problems! -(IBAction) rotate3 { NSString *number = [dayArray initWithArray:(NSArray *)dayArray]; NSArray *array = [[NSArray alloc] initWithObjects: @"0", @"1", @"2", @"3", @"4", @"5" ,@"6", @"7", @"8",@"9",@"10",@"11",@"12",@"13", @"14", @"15", @"16", @"17", @"18", @"19"

How to invalidate an NSTimer that was started multiple times

∥☆過路亽.° 提交于 2019-12-12 04:18:24
问题 I made a practice project in Swift to learn how NSTimer works. There is one button to start the timer and one button to invalidate it. It works fine when I tap each button once. However, when I tap the start timer button multiple times, I am no longer able to invalidate it. Here is my code: class ViewController: UIViewController { var counter = 0 var timer = NSTimer() @IBOutlet weak var label: UILabel! @IBAction func startTimerButtonTapped(sender: UIButton) { timer = NSTimer

Swift - scheduledTimer stopwatch hours portion not working

笑着哭i 提交于 2019-12-12 04:08:40
问题 Bear with me I picked up Swift and Xcode a week ago (Im creating an app to learn Swift during my holidays) I created a timer using scheduledTimer to act as an stopwatch. The seconds and minutes are running fine but I can't get the hours to work. What am I doing wrong? currentTime = 0 timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in self.currentTime += 1 let hoursPortion = String(format: "%02d", CGFloat(self.currentTime) * 60) let minutesPortion = String(format: "%02d"

How to get NSTimer to loop

此生再无相见时 提交于 2019-12-12 04:07:14
问题 I'm trying to learn about NSTimer , using Foundation and printing to the console. Can anybody tell me what I need to do to get the following to work? It compiles with no errors, but does not activate my startTimer method -- nothing prints. My aim is to get one method to call another method to run some statements, and then stop after a set time. #import <Foundation/Foundation.h> @interface MyTime : NSObject { NSTimer *timer; } - (void)startTimer; @end @implementation MyTime - (void)dealloc {

Making a countdown timer and run it in the background

岁酱吖の 提交于 2019-12-12 03:58:16
问题 I want to add a mute button to my app that when the user clicks it, he chooses a duration of the mute and while the mute is enabled the user won't get notifications from my app. I thought NSTimer is a good option, but how can I make a timer with it? And how can I set that the timer will run in the background aswell? Note: I'm using location monitoring in the background. 回答1: I don't think you need a running timer in the background - or any complicated solution: Use a timer when your app is in

NSTimer timerWithTimeInterval not calling selector (Swift)

两盒软妹~` 提交于 2019-12-12 03:45:48
问题 I have tried many approaches that I have found in other questions and any of them are working. My problem is that the timer is not calling selector class MyViewController: UIViewController{ var progressBarTimer = NSTimer() @IBOutlet weak var progress_bar: UIProgressView! override func viewDidLoad() { self.progress_bar.progress = 0 self.progressBarTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(MyViewController.updateProgress(_:)), userInfo: nil, repeats:

NSTimer crashes with bad access

早过忘川 提交于 2019-12-12 03:45:26
问题 I have the following method to update a label which show a simple time up -(void)updateTimeLabel:(NSTimer *)timer{ NSInteger secondsSinceStart = (NSInteger)[[NSDate date] timeIntervalSinceDate:_startTime]; NSInteger seconds = secondsSinceStart % 60; NSInteger minutes = (secondsSinceStart / 60) % 60; NSInteger hours = secondsSinceStart / (60 * 60); NSString *result = nil; if (hours > 0) { result = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds]; } else { result =

How can I make a countdown timer like in a music player?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 03:39:24
问题 I have a label and its value is "03:48". I want to countdown it like a music player. How can I do that? 03:48 03:47 03:46 03:45 ... 00:00 var musictime =3:48 func stringFromTimeInterval(interval: NSTimeInterval) -> String { let interval = Int(interval) let seconds = interval % 60 let minutes = (interval / 60) return String(format: "%02d:%02d", minutes, seconds) } func startTimer() { var duration=musictime.componentsSeparatedByString(":") //split 3 and 48 var count = duration[0].toInt()! * 60

How to make NSTimer and some operations keep working on background?

别等时光非礼了梦想. 提交于 2019-12-12 03:34:45
问题 I m writing ios app on 4.3 simulator and 3.2 xcode The app every minute with timer NSTimer checks news on some websites and if there are news, the app will make alert message with sound "There are something new on ... website!" But if i close app or it goes to sleep, timer stops on background. So, i have read many articles like http://www.codeproject.com/Articles/124159/Hour-21-Building-Background-Aware-Applications How keep NSTimer when application entering background? and non of them helped

NSTimer inside global queue is not called when the app is in the background

我与影子孤独终老i 提交于 2019-12-12 03:28:13
问题 I want to run a selector using NSTimer which contains some network calls and some other tasks. I want to do that on global queue. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSTimer * myTimer=[[NSTimer alloc]init]; myTimer = [NSTimer timerWithTimeInterval:10*60 target:self selector:@selector(syncGroupAutomatically) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSRunLoopCommonModes]; [[NSRunLoop currentRunLoop] run]; }); -