nstimer

NSTimer inside custom tableViewCell

[亡魂溺海] 提交于 2019-12-20 03:52:41
问题 I'm activating a function in my custom cell class from a viewController. The custom cell class looks like this: import UIKit class TableViewCell: UITableViewCell { var counter = 10 class func timerStarted(){ var timer = NSTimer() timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "update", userInfo: nil, repeats: true) } class func update(){ let cell = TableViewCell() var count = cell.counter count = --count println(counter) } } The problem is that the variable counter

Extra argument 'selector' in call - NSTimer scheduledTimerWithTimeInterval

久未见 提交于 2019-12-20 02:37:09
问题 I have the following line of code: changeColour = NSTimer.scheduledTimerWithTimeInterval(TIMES, target: self, selector: "changeColourOfPage", repeats: true) but it gives the error "Extra argument 'selector' in call" when I change the TIMES variable to a number like 1.0 , it works fine. The variable TIMES is set to 1.0 . Is this just a glitch, or am I being stupid about something? I need to use it to run a method at random intervals. Please help! 回答1: It looks like you're missing the userInfo

Correct way to release NSTimer?

末鹿安然 提交于 2019-12-20 01:10:20
问题 What is the correct way to release a NSTimer in my dealloc method ? It was created with the following code ? -(void)mainTimerLoop { mainTimer = [NSTimer scheduledTimerWithTimeInterval:1/10 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES]; } Thanks 回答1: you have a really good answer about NSTimer here How do I use NSTimer? there they talk about stoping a repeating NSTimer doing [myTimer invalidate]; 回答2: The way you're doing it, you won't ever hit dealloc . A timer retains

iPhone 4 is there an absolutely certain way to have a long term NSTimer fire

本小妞迷上赌 提交于 2019-12-19 10:34:11
问题 I keep having troubles with my NSTimers and background selectors. It is driving me nuts and takes a very long time to try out each tweak. To preserve my sanity, and the sanity of future generations of cocoa programmers, I'm asking this question: Is there an absolutely 100% sure way to have a scheduled, long-term timer fire at a later point in time, regardless of whether it was called from a background thread, main thread, etc? It seems that I keep having to solve the same problem over and

How to Fix Error with a Swift NSTimer Calling Its Selector

主宰稳场 提交于 2019-12-19 03:24:15
问题 I'm getting a runtime error of: 2014-07-15 16:49:44.893 TransporterGUI[1527:303] -[_TtC14TransporterGUI11AppDelegate printCountdown]: unrecognized selector sent to instance 0x10040e8a0 when I use the following Swift code to fire a timer: @IBAction func schedule(sender : AnyObject) { var startTime = startDatePicker.dateValue.timeIntervalSinceDate(NSDate()) var endTime = endDatePicker.dateValue.timeIntervalSinceDate(startDatePicker.dateValue) var startDate = NSDate.date() let params = [

Pausing timer when app is in background state Swift

故事扮演 提交于 2019-12-18 15:55:12
问题 My ViewController.swift func startTimer() { timer = NSTimer().scheduleTimerWithTimerInvterval(1.0,target: self,selctor: Selector("couting"),userinfo: nil, repeats: true) } func pauseTimer() { timer.invalidate() println("pausing timer") } and this is appDelegate.swift func applicateWillResignActive(application: UIApplication) { viewController().pauseTimer() println("closing app") } It is printing pausing timer and closing app but when I open again I see it never paused. How do I do it

Difference in scheduling NSTimer in main thread and background thread?

走远了吗. 提交于 2019-12-18 10:53:06
问题 When I call scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: on the main thread and set time interval to 5 seconds code below timer gets executed, and after 5 seconds timer selector is called. But if I try same in some background thread, the code below scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: will not be executed, it will wait for the timer to fire and then gets executed. Of course, in order to run the timer in the background thread, I first got an

Difference in scheduling NSTimer in main thread and background thread?

醉酒当歌 提交于 2019-12-18 10:52:06
问题 When I call scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: on the main thread and set time interval to 5 seconds code below timer gets executed, and after 5 seconds timer selector is called. But if I try same in some background thread, the code below scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: will not be executed, it will wait for the timer to fire and then gets executed. Of course, in order to run the timer in the background thread, I first got an

How to update UITableViewCells using NSTimer and NSNotificationCentre in Swift

随声附和 提交于 2019-12-18 10:46:22
问题 NOTE: Asking for answers in Swift please. What I'm trying to do: Have tableview cells update every 1 second and display a real-time countdown. How I'm doing it currently: I have a tableview with cells that contain a label. When the cells are generated, they call a function that calculates the time between today and a stored target date, and it displays the countdown time remaining in the label. To get the cells to update the label every second, I use an NSTimer that reloads the tableview

Why timer stops when scrolling in UIWebView iPhone? [duplicate]

偶尔善良 提交于 2019-12-18 03:41:47
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: UIScrollView pauses NSTimer until scrolling finishes I am having a bit of trouble figuring out why the NSTimer stops as soon as I scroll in the UIWebView. Please take a look at the following code (I know this isn't a homework site, but I honestly am stuck): - (void)viewDidLoad { [super viewDidLoad]; NSString *address = @"http://en.m.wikipedia.org/wiki/"; NSURL *url = [NSURL URLWithString:address]; NSURLRequest