如何为NSTimer赋值 [英] How to value for NSTimer

查看:70
本文介绍了如何为NSTimer赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个用户必须选择时间的应用程序,例如5分钟,10分钟或15分钟,然后计时器将运行约15秒并调用另一个函数.计时器应每15分钟运行一次秒,我已经实现了上面的事情,它正在工作,我唯一没有得到的是如何在15秒的时间范围内运行NSTimer 5分钟或10分钟,就像计时器应该在15秒左右的时间内运行时间间隔, 5分钟后,它应该停止.

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 stop.

推荐答案

您每15秒钟触发一次计时器,并在计时器触发方法中继续添加时间,当时间达到10分钟(或15分钟)时,停止计时器.

You fire timer every 15 seconds and in the timer fire method, keep adding the time and when time reaches 10 mins (or 15 mins), stop the timer.

[NSTimer scheduledTimerWithTimeInterval:15.0f target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];

-(void) timerFireMethod:(NSTimer *) theTimer {
    _elapsedTime += 15.0f;
    if (_elapsedTime >= 5.0 * 60) {
        // elapsed time is 5 mins.
        [theTimer invalidate];
    }
}

这篇关于如何为NSTimer赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆