nstimer

Press-and-hold button for “repeat fire”

我的未来我决定 提交于 2019-11-27 13:57:32
I have referred to countless other questions about a press-and-hold button but there aren't many related to Swift. I have one function connected to a button using the touchUpInside event: @IBAction func singleFire(sender: AnyObject){ //code } ...and another function that is meant to call the function above repeatedly while the same button is held down, and stop when the button is no longer pressed: @IBAction func speedFire(sender: AnyObject){ button.addTarget(self, action: "buttonDown:", forControlEvents: .TouchDown) button.addTarget(self, action: "buttonUp:", forControlEvents: .TouchUpOutside

How to stop NSTimer

给你一囗甜甜゛ 提交于 2019-11-27 13:53:37
Hey so i am just making an example application and i am having a little trouble, So i have a table view and then i have a few rows and when a user clicks a row it takes them to a new view. On this view i have a button to play music. I am using a timer to make a slider bar increase based on music duration and remaining time. Now my problem is, what do i have to put so that when i go back to the table view via the top left button, that the NSTimer stops? this is what i have so far, i cannot get a repeat: YES timer to stop. #import "SecondViewController.h" @implementation SecondViewController

How Can I Start And Stop NSTimer?

泪湿孤枕 提交于 2019-11-27 12:46:38
问题 I develop Stop Watch Application. In my application, there are Two UIButtons , StartBtn and StopBtn , And also I use NSTimer . Now, i want to start NSTimer when user click on StartBtn and also stop when your click on StopBtn . I know that NSTimer is stopped by [MyTimerName invalidate]; method but I don't know how to start NSTimer again? 回答1: The NSTimer class is a bit awkward to use; rather than separating the creation/destruction from the start/stop, it's all rolled together. In other words

iphone - NSTimers in background

梦想的初衷 提交于 2019-11-27 12:13:50
Im developing an app that has to run in the background. It's a location based app, so it runs all the time, the OS doesn't kill it. It should send some info every 10 secs(just for debugging), I set a timer once its in the background. I set a breakpoint in the function that should be executed every 10 secs, which is never called, but if I pause the app and then continue the timer is called, and then the timer is executed every 10 secs without problems, weird right? I thought that the timer would be executing anyway when I wasn't debugging, but it isn't, same thing as if I didn't pause the

NSTimer not firing when runloop is blocked

旧城冷巷雨未停 提交于 2019-11-27 11:56:27
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 scrolling still stalls the timer even though the elapsed time will be updated correctly in the end... and

How to stop NStimer event? [duplicate]

吃可爱长大的小学妹 提交于 2019-11-27 11:27:08
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: NSTimer doesn't stop In my application I am using NStimer to call an animation function every 3 seconds. I want to stop this timer and called another event while the timer is still running. Is this possible? 回答1: @interface NSTimer *autoTimer; @implementation // Start timer autoTimer = [NSTimer scheduledTimerWithTimeInterval:(3.0) target:self selector:@selector(autoTimerFired:) userInfo:nil repeats:YES]; // Stop

Passing parameters to the method called by a NSTimer

点点圈 提交于 2019-11-27 10:55:06
How can I pass a parameter to the method called by a NSTimer? My timer looks like this: [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(updateBusLocation) userInfo:nil repeats:YES]; and I want to be able to pass a string to the method updateBusLocation. Also, where am supposed to define the method updateBusLocation? In the same .m file that I create the timer? EDIT: Actually I am still having problems. I am getting the error message: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' * -[MapKitDisplayViewController updateBusLocation]:

Determine if UIView is visible to the user?

放肆的年华 提交于 2019-11-27 09:49:16
问题 is it possible to determine whether my UIView is visible to the user or not? My View is added as subview several times into a Tab Bar Controller . Each instance of this view has a NSTimer that updates the view. However I don't want to update a view which is not visible to the user. Is this possible? Thanks 回答1: You can check if: it is hidden, by checking view.hidden it is in the view hierarchy, by checking view.superview != nil you can check the bounds of a view to see if it is on screen The

Getting Current Time in string in Custom format in objective c

十年热恋 提交于 2019-11-27 09:39:54
问题 I want current time in following format in a string. dd-mm-yyyy HH:MM How? 回答1: You want a date formatter. Here's an example: NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"dd-MM-yyyy HH:mm"]; NSDate *currentDate = [NSDate date]; NSString *dateString = [formatter stringFromDate:currentDate]; 回答2: Either use NSDateFormatter as Carl said, or just use good old strftime , which is also perfectly valid Objective-C: #import <time.h> time_t currentTime = time

NSTimer not firing when NSMenu is open in Swift

点点圈 提交于 2019-11-27 09:07:04
I have a timer that runs to restart an alarm once it goes off. alarm = NSTimer.scheduledTimerWithTimeInterval( 60 * minutesConstant + secondsConstant, target:self, selector: Selector("endSession"), userInfo: nil, repeats:false) Its selector function sets a mode flag, and calls the original function that set the alarm with new minutes and seconds constants, and also sends a user notification that the session has restarted. I have a menu item that gets updated with the remaining time So I've been opening it to check that my alarm does indeed restart, and that the notification shows once it hits