nstimer

Swift NSTimer didn't work

隐身守侯 提交于 2019-12-23 04:58:04
问题 I make a "Command Line Tool", and I need use NSTimer. I start the timer, but it doesn't work... import Foundation class ct : NSObject { func start() { var timer = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: Selector("update"), userInfo: nil, repeats: true) } func update() { println("test timer"); } } var a = ct(); a.start() while(true) { sleep(10000000) } 回答1: NSTimer needs a run loop to work properly, a CLI doesn't have/need one by default. Call CFRunLoopRun() to

How to value for NSTimer

▼魔方 西西 提交于 2019-12-23 04:39:17
问题 I am making on application in which user have to select the time, example 5 min or 10 min or 15 min and after that the timer will run arround 15 seconds and will called another function.Timer should have to run after every 15 seconds, i have implemented the above the things and it is working, The only thing which i am not getting is that how to run NSTimer for 5 mins or 10 mins with 15 seconds timeframe, Like timer should run time interval for arround 15 seconds and after 5 minutes it should

Timer vs ASIHTTPRequest - find optimal solution

蓝咒 提交于 2019-12-23 04:28:26
问题 The code is shown as below, I have a button once you click it activates timer and timer calls method every 4sec. However, sometimes 4 sec is not enough for server to return the data. However, increasing the timer value is not also good solution if server returns data in 1 sec and would not good for user to wait longer. I do not know what is best/optimal solution in this case. -(IBAction)play:(id)sender{ timer=[NSTimer scheculedWith TimerInterval(4.0) target:(self)selector:@selector

NSTimer blocks other animations

梦想的初衷 提交于 2019-12-23 03:14:50
问题 Description I have a NSTimer that updates an UILabel every second. I have another UIImageView that slides in the screen when a UIButton is pressed. Issue The problem is that when the NSTimer updates the UILabel , the animation of the UImageView stops from completing. Question Please can you tell me how can i update the timer without messing with the other animations? 回答1: This is a common symptom of having auto layout turned on but are probably trying to slide it across the screen by

NSTimers causing leaks

混江龙づ霸主 提交于 2019-12-23 02:38:44
问题 I've read up a lot about NSTimers, but I must be doing something very wrong with them, because it's practically all the leaks that show up in the Leaks Instrument. The "Responsible Frame" column says -[NSCFTimer or +[NSTimer(NSTimer). So here's how I have an NSTimer set up in my main menu. I shortened it up to just show how the timer is setup. .h - @interface MainMenu : UIView { NSTimer *timer_porthole; } @end @interface MainMenu () -(void) onTimer_porthole:(NSTimer*)timer; @end .m - (in

NSTimer: floating point value can not be converted to UInt8 because it is greater than UInt8.max

≯℡__Kan透↙ 提交于 2019-12-23 01:45:11
问题 My code returns the error: fatal error: floating point value can not be converted to UInt8 because it is greater than UInt8.max. The code is being called when a button is pressed (in a different swift file) but I know that the problem wasn't with calling the function so I didn't include it. code: //starts the timer func startTimer(sender: AnyObject) { if !timer.valid { timer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: sender, selector: Selector(updateTime()), userInfo: nil, repeats

Animation stops when scrolling in UIScrollView

六月ゝ 毕业季﹏ 提交于 2019-12-22 06:57:14
问题 So I am trying to make a game where the user must scroll down as fast as they can in order to escape a "block" that grows infinitely bigger. Here is my problem: I am using a UI ScrollView as my mechanism for scrolling with a normal UI View as a subview. I have a time set to fire every 0.005 seconds that increases the height of both the "block" and the content height of the scroll view (so that the user can technically scroll infinitely). The problem is that whenever the user begins to scroll,

How can I update my NSTimer as I change the value of the time interval

只谈情不闲聊 提交于 2019-12-22 05:08:07
问题 I have an NSTtimer implemented and it's working fine. I also have the time interval argument connected to a UISlider for the iPhone . However when I change it's value the NSTimer is still running at the original time interval it does not get updated. How can I implement an NSTimer and have it change it's time interval as the value of my UISlider changes. Below is the line I am using for the NSTimer . [NSTimer scheduledTimerWithTimeInterval:mySlider.value target:self selector:@selector

Display StopWatch Timer in UITableViewCell dynamically

流过昼夜 提交于 2019-12-21 17:29:00
问题 I want to hold timer values and Display it from start in new UITableViewCell but my problem is that I am successfully able to display stopwatch timer on first Cell but when I am trying to add a new cell in UITableView so my timer is set to second cell and I am unable to define how to keep my first timer alive. I thought of managing an Array but I want to call reload TableData everytime, but I think that is bad :( I tried work around as below but I am not figuring out how to show timerValue on

NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats doesn't invoke the method

戏子无情 提交于 2019-12-21 11:55:30
问题 The timer never invokes the method. What am I doing wrong ? This is the code: NSTimer *manualOverlayTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(hideManual) userInfo:nil repeats:NO]; method: -(void)hideManual thanks 回答1: It was a thread issue. I've fixed with: dispatch_async(dispatch_get_main_queue(), ^{ // Timer here }); 回答2: You don't need an NSTimer for a task of this sort. To hide your view object after a specific period of time on main thread you can