nstimer

multiple countdown timers inside uitableview

邮差的信 提交于 2019-12-07 06:19:58
问题 How do I go about this task? Basically, I will have an array of "seconds int" listed inside the UITableView. So how can I assign each "seconds int" to countdown to zero? The possible problems I'm seeing is the timers not being updated when the cell is not yet created. And how do I instantiate multiple independent NSTimers updating different ui elements? I'm quite lost here, so any suggestions is greatly appreciated. for visual purposes, I want to have something like this: 回答1: From the image,

Trivial “+[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: unrecognized selector” error

♀尐吖头ヾ 提交于 2019-12-07 06:04:24
问题 I am banging my head against an odd error after a move to 10.12/Sierra and Xcode 8.1: +[NSTimer scheduledTimerWithTimeInterval:repeats:block:]: unrecognized selector sent to class 0x7fff78f1fa88 The most minimal code (default settings of create a new project) to reproduce this is: // AppDelegate.m // #import "AppDelegate.h" @interface AppDelegate () @property (weak) IBOutlet NSWindow *window; @property (strong, nonatomic) NSTimer * timer; @end @implementation AppDelegate - (void

Error - Thread 1: signal SIGABRT (unrecognized selector sent to instance) [duplicate]

瘦欲@ 提交于 2019-12-07 03:35:29
This question already has answers here : Unrecognized selector sent to instance NSTimer Swift (3 answers) Closed 4 years ago . I'm making an app where you need to indicate the amount of time that a label appears for and that amount of time is counted down at the bottom of the page. When I run my app on the Xcode simulator, the chronometre label displays "Optional (*indicated number)" when I want it to only display the indicated number. Once it's displayed for a second, I get taken to my App Delegate and it says Thread 1: signal SIGABRT . The following error is also shown: 2015-02-22 21:05:50

iOS的定时器用法

大憨熊 提交于 2019-12-07 01:23:36
定时器在项目中还是经常用到的,很多情况下为了省事我们都是在主线程中直接用,但这样经常会造成阻塞,影响定时器的准确性,对时间精度要求比较高的地方还会给人很不好的体验,比如卡顿等等,所以,定时器的使用最好放在子线程中,下面就记录几种定时器的用法: 1、NSThread NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(newThread) object:nil]; [thread start]; - (void)newThread{ @autoreleasepool{ [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(requestMessages) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] run]; } } 2、GCD 首先定义timer: 这里有一点疑惑:timer若作为成员变量(定义放在@interface里面)定时器可以正常使用,但是在方法里面再去定义的定义的话定时器就完全不起作用了,还请知道的原因的小伙伴多多指教: NSTimeInterval period = 60.0; //设置时间间隔 dispatch

iOS 定时器

↘锁芯ラ 提交于 2019-12-07 01:23:17
iOS里面使用的定时器类型一般有三种NSTimer、CADisplayLink、GCD。 1、最精准的定时器 - GCD #import "ViewController.h" @interface ViewController () // 必须要有强引用,不然对象会被释放 @property (nonatomic , strong) dispatch_source_t timer ; @end @implementation ViewController -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ NSLog(@"__%s__",__func__); #warning 重复执行的GCD定时器 // 1、基于GCD的定时器,创建timer对象: // 参数一:source的类型DISPATCH_SOURCE_TYPE_TIMER 表示定时器类型 // 参数二:描述内容,比如线程ID // 参数三:详细描述内容 // 参数四:队列,决定GCD的队列在哪个线程执行 dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0

Set an NSTimer to fire once in the future

我的未来我决定 提交于 2019-12-07 00:37:31
问题 How do I set up an NSTimer to fire once in the future (say, 30 seconds). So far, I have only managed to set it so it fires immediately, and then at intervals. 回答1: The method you want to use is: + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval) seconds target:(id) target selector:(SEL) aSelector userInfo:(id) userInfo repeats:(BOOL) repeats with repeats == NO arguments and seconds == 30 . This will create the timer and schedule it. It will fire only once, in 30 seconds (and not

NSTimers causing leaks

二次信任 提交于 2019-12-06 21:17:28
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 initWithFrame) - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { timer

Count while in background (NSTimer for more than 3 mins)

半腔热情 提交于 2019-12-06 19:47:25
Is there any way to run NSTimer for more than 3 mins in background? I have to create simple app that uses `locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion)` for scan my beacons. I have run into problem when I needed to check if user is exactly 10 seconds near closest beacon. I created var timer: NSTimer? var lastClosestBeacon: CLBeacon? { didSet { timer?.invalidate() timer = NSTimer.scheduledTimerWithTimeInterval(10, target: self, selector: "showLocalNotification", userInfo: nil, repeats: false) // NSRunLoop.mainRunLoop()

How to “validate” a NSTimer after invalidating it?

亡梦爱人 提交于 2019-12-06 18:29:42
问题 So basically, I have this timer that should be repeated when it receives a key event, and invalidates when the user releases the key. However, I am unable to "validate" the timer back even by calling the addTimer:forMode: in NSRunLoop. Does anyone know why this is happening and how I can fix this? Thanks. 回答1: You cannot use invalidated timer. From Apple Docs: Once scheduled on a run loop, the timer fires at the specified interval until it is invalidated. A non-repeating timer invalidates

Delete NSTimer/UITableViewCell in real time?

一笑奈何 提交于 2019-12-06 16:28:01
问题 I have a UITableView in which I have numerous timers set on each UITableViewCell . Each timer starts from when a user creates a "post" on my application and should expire within 24 hours. However, I want it so that when all 24 hours is over, the UITableViewCell deletes itself in real time but I can't seem to figure out where or when I should be deleting the timer. I have a method that will constantly refresh the timer every second using NSTimer.scheduledTimerWithTimeInterval and it updates