我想在特定时间之后调用一个方法,直到我的应用程序在iphone中打开?

时间:2011-03-28 05:12:40

标签: iphone

我想在每2分钟后调用一个方法, 我该如何应用这样的逻辑?

3 个答案:

答案 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];

希望有所帮助。