在目标C中按时间间隔进行操作 [英] Action with time intervals in Objective C
本文介绍了在目标C中按时间间隔进行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的iPhone应用程序中,我要从其中一种视图打印NSLog(@"Refreshed");每1分钟间隔一次.我该怎么办?
In my iPhone app,from one of the views I want to print NSLog(@"Refreshed"); in all 1 minute interval. How can I do that?
推荐答案
像下面这样使用 NSTimer
:-
在您的 .h 类中定义NSTimer
Define NSTimer in your .h class
NSTimer * TimeOfActiveUser;
NSTimer *TimeOfActiveUser;
在 .m
- (void)viewWillAppear:(BOOL)animated
{
TimeOfActiveUser = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(actionTimer) userInfo:nil repeats:YES];
}
-(void)actionTimer
{
//Print your log
}
如果您想停止NSTIMER ..?设置其他喜欢的动作
-(void)stopTimer
{
[TimeOfActiveUser invalidate];
TimeOfActiveUser = nil;
}
希望它对您有帮助,我是朋友..幸福的编码:)
Hope its help's you my Friend.. happy coding :)
这篇关于在目标C中按时间间隔进行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文