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

Sle*_*lee 4 iphone objective-c ios

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

far*_*igo 12

您可以使用NSTimer:

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

[NSTimer scheduledTimerWithTimeInterval:300.0f
             target:self
         selector:@selector(updateMethod:)
         userInfo:nil
         repeats:YES];
Run Code Online (Sandbox Code Playgroud)

然后创建更新方法:

- (void)updateMethod:(NSTimer *)theTimer {
    // Your code goes here
}
Run Code Online (Sandbox Code Playgroud)