Tag: 计时器

当tableView滚动时,tableViewCells中的运行计时器被覆盖

我已经试过多次询问这个问题,但是我一直没能解释发生了什么事情。 也许一些屏幕截图可能有帮助。 我只能发布一个,因为我没有足够的声望点。 在tableview滚动后截图 您可以看到其中一个定时器(2)已被重置。 我试图解决这个多种方式没有成功。 下面是将定时器放入tableview单元的代码: -(void) calculateTimer:(NSTimer *)theTimer { self.timerItem = [theTimer userInfo]; // for date only cell if(self.timerItem.timerType == 0){ [theTimer invalidate]; } for (NRCItemCell *cell in [self.tableView visibleCells]) { NSIndexPath *ip = [self.tableView indexPathForCell:cell]; NSUInteger row = [[[NRCItemStore sharedStore]allItems] indexOfObjectIdenticalTo:self.timerItem]; if (row == ip.row){ [self configureTimers:cell forRowAtIndexPath:ip]; cell.timer.text = self.timerItem.timerOutput; cell.timerName.text […]

NSTimer不会失效

我有一个问题,使我的计时器无效。 @property (nonatomic, strong) NSTimer *timer; 在我的成功块内,我正在主线程上分配和设置我的计时器: dispatch_async(dispatch_get_main_queue(), ^{ self.timer = [NSTimer scheduledTimerWithTimeInterval:[Config refreshInterval].integerValue target:self selector:@selector(methodThatHasABlockCalledMentionedAbove) userInfo:nil repeats:NO]; }); 在我的textFieldDidBeginEditing我无效我的计时器是这样的: dispatch_async(dispatch_get_main_queue(), ^{ [self.timer invalidate]; self.timer = nil; }); 我的方法仍然在计时器上执行。 有什么收获?

Swift Timer.scheduledTimer()不起作用

我在我的快速应用程序中有两个意见。 我正在执行一个赛如下。 ViewController.swift —————–> GameViewController.swift 当加载GameViewController时,一个值数组也从ViewController.swift传递给GameViewController.swift 计时器应该在GameViewController.swift中初始化 我试图初始化一个计时器,并通过它调用一个方法,但它不起作用。 以下是我的代码片段。 ViewController.swift func signIn(difficultyLvl:String){ let username = usernameTxt.text let password = passwordTxt.text let url = URL(string: "http://192.168.1.106/speed/scoreBoardController.php?username="+username!+"&password="+password!+"&action=SIGNIN") let task = URLSession.shared.dataTask(with: url!) {(data, response, error) in let isPassed = String(data: data!, encoding:.utf8)?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) var gameViewControllerParams = [Int: [String: String]]() gameViewControllerParams[0] = ["userId" : isPassed!] gameViewControllerParams[1] = ["difficultyLvl" […]

在iOS的特定时间启动本地通知

我正在尝试创build一个计时器,触发本地通知在用户设置的时间closures。 我遇到的问题是我无法想出一个办法,可以设置本地通知在下午7:00点closures。 在研究这个问题时,几乎所有的方法都是在当地通知从当前date起的一定时间内发生的。 我正在尝试让用户select晚上7点,然后在那个时候通知。 从逻辑上讲,通过获得最后的时间(用户select的值)可以实现这一点 – 当前的时间会给你时间差。 但我不完全确定如何做到这一点。 对这个话题的任何帮助将非常感谢,谢谢。 以下是我目前用来触发本地通知的代码。 let center = UNUserNotificationCenter.current() content.title = storedMessage content.body = "Drag down to reset or disable alarm" content.categoryIdentifier = "alarm" content.userInfo = ["customData": "fizzbuzz"] content.sound = UNNotificationSound.init(named: "1.mp3") content.badge = 1 let trigger = UNTimeIntervalNotificationTrigger(timeInterval: timeAmount, repeats: false) let request = UNNotificationRequest(identifier: "requestAlarm", content: content, trigger: […]

如何让一个button持续不断地调用一个函数(SpriteKit)

我正在使用sprite套件进行游戏,当按住左/右移动button时,我希望我的angular色在屏幕上移动。 问题在于,只有在轻按button时,他才会移动,而不是保持。 我到处寻找解决scheme,但似乎没有任何工作! 这是我的代码; class Button: SKNode { var defaultButton: SKSpriteNode // defualt state var activeButton: SKSpriteNode // active state var timer = Timer() var action: () -> Void //default constructor init(defaultButtonImage: String, activeButtonImage: String, buttonAction: @escaping () -> Void ) { //get the images for both button states defaultButton = SKSpriteNode(imageNamed: defaultButtonImage) activeButton = […]

iOS计时器在后台

我想在我的iOS应用程序启动一个计时器,当应用程序在后台运行,当应用程序closures。 定时器必须每隔30分钟检查一次新的通知。 在计时器function中,他们每30分钟调用另一个函数showNotification()。 我该如何做这个计时器,以及在应用程序未在后台运行/运行时,我必须在哪个位置调用计时器。

是否有可能刷新今日小工具的计时器?

我想知道是否有可能更新当前小部件中的计时器的文本标签。 我看了一下,但没有任何帮助。

iOS每天运行一次

这个应用程序背后的想法很简单:下载一个文件。 然而,这个应用程序将为那些不总是在互联网访问范围内的人,所以我需要它知道,在上午9:00,下载文件到硬盘驱动器。 应用程序中会有一个button来手动执行,但是我已经有了这个工作。 据我所知,如果可能的话,这将是困难的。 我知道iOS不喜欢多任务处理,但我也意识到它确实允许后台计时器function。 我愿意接受任何人可能需要完成的build议,即使这意味着要编写一个单独的应用程序。 谢谢。 编辑:我看到有可能与通知,甚至可能是日历。 这一类的想法也受到欢迎。 编辑2:我也读了一些关于启动应用程序的外部服务器,但没有给出任何描述。

SpriteKit – 创build一个计时器

我如何创build一个计时器,每隔两秒钟触发一次,将屏幕上的HUD上的分数递增1? 这是我对HUD的代码: @implementation MyScene { int counter; BOOL updateLabel; SKLabelNode *counterLabel; } -(id)initWithSize:(CGSize)size { if (self = [super initWithSize:size]) { counter = 0; updateLabel = false; counterLabel = [SKLabelNode labelNodeWithFontNamed:@"Chalkduster"]; counterLabel.name = @"myCounterLabel"; counterLabel.text = @"0"; counterLabel.fontSize = 20; counterLabel.fontColor = [SKColor yellowColor]; counterLabel.horizontalAlignmentMode = SKLabelHorizontalAlignmentModeCenter; counterLabel.verticalAlignmentMode = SKLabelVerticalAlignmentModeBottom; counterLabel.position = CGPointMake(50,50); // change x,y […]