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



我想调用一个特定的方法在我的UIView代码说每5分钟-我怎么做到这一点?

你可以使用NSTimer:

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

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

然后创建更新方法:

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

您可以使用NSTimer来完成此操作。

http://developer.apple.com/library/mac/文档/可可/引用/基金/类/NSTimer_Class/引用/NSTimer.html

特别timerWithTimeInterval:target:selector:userInfo:repeats:类方法。

有一个简单的方法可以做到这一点,在您的更新方法

-(void)update{
     //Your update methods here
     [self performSelector:@selector(update) withObject:nil afterDelay:300.0];
}

最新更新