Tag: nstimer

当popup到view2时如何恢复定时器

我的应用程序有3个意见 在view1中只有一个button(play level 1)推动veiw2并更新view2中的titlelabel 当view2加载并出现一个计时器开始倒计时并更新view2本身的另一个标签,也view2有button,暂停定时器,并推动view3 在view3中只有一个buttonpopup到view2并恢复定时器 我的问题是,当我从view3popupview2计时器仍然暂停 请帮忙吗? 感谢和亲切的问候。 view1.h #import <UIKit/UIKit.h> @interface view1 : UIViewController -(IBAction)nextpage; @end view1.m #import "view1.h" #import "view2.h" @interface view1 () @end @implementation view1 -(IBAction)nextpage{ view2 *obj = [[view2 alloc] init]; [self.navigationController pushViewController:obj animated:YES]; [obj.leveltitle setText:@"Level"]; obj.time=10; } – (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if […]

如何将时间添加到iOS项目的倒数计时器

我有一个游戏在哪里使用倒数计时器,当计时器到时,你是一个博弈观点。 我想添加一个function,如果他们点击一个button,它会增加像1,2或3秒钟的计时器。 我已经有了计时器的代码(下面),但是我只需要知道如何给计数器添加更多的时间。 我想到了这一点,我不得不说,当意见转换时,需要考虑增加的时间。 码: -(IBAction)Ready:(id)sender { [self performSelector:@selector(TimerDelay) withObject:nil afterDelay:1.0]; [self performSelector:@selector(delay) withObject:nil afterDelay:36.5]; } -(void)TimerDelay { MainInt = 36; timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDownDuration) userInfo:nil repeats:YES]; if (timer == 0) { [timer invalidate]; } } -(void)countDownDuration { MainInt -= 1; seconds.text = [NSString stringWithFormat:@"%i", MainInt]; } -(void)delay { GameOverView1_4inch *second= [self.storyboard instantiateViewControllerWithIdentifier:@"GameOverView1"]; […]

定时器vs ASIHTTPRequest – find最佳解决scheme

代码如下所示,一旦你点击一个button,每4秒激活一次定时器和定时器的调用方法。 但是,有时4秒是不够的服务器返回数据。 但是,如果服务器在1秒内返回数据并且不利于用户等待更长时间,则增加计时器值也不是好的解决scheme。 在这种情况下,我不知道什么是最佳/最佳解决scheme。 -(IBAction)play:(id)sender{ timer=[NSTimer scheculedWith TimerInterval(4.0) target:(self)selector:@selector(httpRequest) userinfo:nil repeats:YES] } -(void)httpRequest{ _weak ASIHTTPRequest *request1 = [ASIHTTPRequest requestWithURL:url1]; [request1 setCompletionBlock:^{ NSString *responseString1 = [request1 responseString]; //dispatch_async(backgroundProcess1,^(void){ [self plotOverlay1:responseString1]; //}); }]; [request1 setFailedBlock:^{ NSError *error=[request1 error]; NSLog(@"Error: %@", error.localizedDescription); }]; [request1 startAsynchronous]; }

查看ApplicationWillResignActive中的控制器variables

我试图让我的计时器在后台运行,通过在进入背景时保存磁盘的时间,并在进入前台时检索它。 每个视图控制器都有一个定时器和一个由用户指定的timeInterval。 问题是,我不知道如何访问timeIntervalvariables。 我想我可以通过使用这样的东西来获得时间的差异(这会工作吗?): NSTimeInterval idleTime = [dateReturnedToForeground timeIntervalSinceDate:dateEnteredBackground]; NSTimeInterval elapsedTime = [[NSDate date] timeIntervalSinceDate:startDate]; elapsedTime -= idleTime; 每个视图控制器(和定时器/时间间隔)是这样访问的: -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ DetailViewController *detailVC; if (![self.detailViewsDictionary.allKeys containsObject:indexPath]){ detailVC = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil]; [self.detailViewsDictionary setObject:detailVC forKey:indexPath]; detailVC.context = self.managedObjectContext; }else{ detailVC = self.detailViewsDictionary[indexPath]; } Tasks *task = [[self fetchedResultsController] objectAtIndexPath:indexPath]; detailVC.testTask = task; [[self navigationController] […]

无法失效(停止)NSTimer

可能重复: NSTimer不停止 我正在使用NSTimer更新播放audio时滑块的值。 if (sliderUpdateTimer) { [sliderUpdateTimer invalidate]; sliderUpdateTimer=nil; } sliderUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateSliderForAudio) userInfo:nil repeats:YES]; 一旦audio完成播放我无效的audio播放器委托方法中的计时器。 -(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{ NSLog(@"audioPlayerDidFinishPlaying"); [player release]; audioPlayer=nil; [sliderUpdateTimer invalidate]; [sliderUpdateTimer release]; sliderUpdateTimer=nil; } 委托方法正在调用,但计时器不停止….我只有一个线程上运行计时器。 但是,定时器仍然不会停止….在这方面的任何帮助是值得欢迎的…

NSTimer在后台的行为(addTimer:,beginBackgroundTaskWithExpirationHandler :)

Xcode 6.3.1 ARC已启用,适用于iOS 8.3 我需要帮助了解一个奇怪的行为,当我尝试在应用程序进入后台后维护一个单例共享计时器的时候遇到了一个奇怪的行为。 以前我不关心这个NSTimer,因为它使用后台位置服务在后台更新用户位置。 但是,我想解决的情况是用户在后台或位置更新时拒绝位置更新。 位置和计时器为我的应用程序携手共进。 我在下面的主题和网站post中通过了相当多的信息。 苹果公司的后台执行 iOS 7 Background App Refresh Tutorial http://www.infragistics.com/community/blogs/stevez/archive/2013/01/24/ios-tips-and-tricks-working-in-the-background.aspx 如何让我的应用程序在后台运行NSTimer? 如何在后台线程上创buildNSTimer? 计划NSTimer当应用程序在后台? Background Modes Tutorial: Getting Started iPhone – 背景调查事件 在这些信息之外,我能够推导出(2)使计时器运行约8小时,而没有iOS在180秒之后终止应用程序的方法。 (3分钟)的执行时间,苹果公司的文件承诺。 这里是代码: AppDelegate.h (方法#1或#2未更改) #import <UIKit/UIKit.h> @interface MFAppDelegate : UIResponder <UIApplicationDelegate> { UIBackgroundTaskIdentifier bgTask; NSInteger backgroundTimerCurrentValue; } @property (retain, nonatomic) NSTimer *someTimer; @end AppDelegate.m (方法#1) <… […]

在导航时保持定时器在另一个页面上运行

当你切换到其他页面并完成其他任务时,我试图保持一个计时器在另一个页面上运行,本质上保持一个时钟,以执行任务需要多长时间。 每当我切换到另一个页面时,它将定时器重置为启动的时间,并且对于我试图保留的其他页面上的某些开关也是如此。 有任何想法吗? 故事板的屏幕截图: 目前代码: // // ViewController.m #import "ViewController.h" @interface ViewController () @end @implementation ViewController – (IBAction)start{ ticker = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self “selector:@selector(showActivity) userInfo:nil repeats:YES]; } – (IBAction)reset{ [ticker invalidate]; time.text = @" 0:00"; } – (void)showActivity{ int currentTime = [time.text intValue]; int newTime = currentTime + 1; time.text = [NSString stringWithFormat:@"%d", newTime]; } […]

uitableview内的多个倒计时定时器

我如何去做这个任务? 基本上,我将在UITableView中列出一个“秒诠释”数组。 那么我怎样才能把每个“秒诠释”倒计时到零? 我看到的可能的问题是计时器没有被更新时,单元格尚未创build。 我怎么实例化多个独立的NSTimers更新不同的UI元素? 我很迷茫,所以有什么build议,非常感谢。 为了视觉目的,我想要这样的东西:

全局队列中的定时器不在iOS中调用

-(void)viewDidLoad{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [NSTimer scheduledTimerWithTimeInterval:0.10 target:self selector:@selector(action_Timer) userInfo:nil repeats:YES]; } ); } -(void)action_Timer{ LOG("Timer called"); } action_Timer没有被调用。 我不知道为什么。 你有什么主意吗?

NSTimer在一个序列中有多个时间间隔

在不创build多个NSTimer实例的情况下,如何实现一个NSTimer来以一个序列中的不同间隔触发特定或多个方法。 例如method1(0.3秒),method2(0.5),method3(0.7)等等。 如果有人可以请分享任何示例代码,我将不胜感激。