我想在每2分钟后调用一个方法, 我该如何应用这样的逻辑?
答案 0 :(得分:4)
使用NSTimer对象。这里已经讨论了很多,所以我不会重复所有这些 - 只需在右上角的搜索框中搜索“NSTimer”。 : - )
答案 1 :(得分:2)
您可以使用timer ..
[NSTimer scheduledTimerWithTimeInterval:120.0 target:self selector:@selector(yourFunction:) userInfo:nil repeats:YES];
.........
..........
-(void)yourFunction:(NSTimer*)timer{
//do your action here
}
答案 2 :(得分:0)
我使用NSTimer
来触发方法。我在最初的viewDidLoad
部分中使用了以下代码:
myTimer = [NSTimer scheduledTimerWithTimeInterval:120.0 target:self selector:@selector(theMethod) userInfo:nil repeats:YES];
希望有所帮助。