在我的UIView中每5分钟调用一次方法

时间:2011-07-07 17:34:53

标签: iphone objective-c ios

我想在我的UIView代码中调用某个方法,每隔5分钟调用一次 - 我该如何实现?

3 个答案:

答案 0 :(得分:12)

您可以使用NSTimer:

将以下内容放入viewDidLoad(其中300是秒数):

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

然后创建更新方法:

- (void)updateMethod:(NSTimer *)theTimer {
    // Your code goes here
}

答案 1 :(得分:2)

您可以使用NSTimer执行此操作。

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html

具体来说, timerWithTimeInterval:target:selector:userInfo:repeats: 类方法。

答案 2 :(得分:0)

在更新方法

中有一种简单的方法可以做到这一点
-(void)update{
     //Your update methods here
     [self performSelector:@selector(update) withObject:nil afterDelay:300.0];
}