在目标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 :)