call method every 5 minutes in my UIView
I want to call a certain method in my UIVi开发者_如何转开发ew code say every 5 minutes - how do I accomplish that?
You can use an NSTimer:
Put the following in your viewDidLoad (where 300 is the number of seconds):
[NSTimer scheduledTimerWithTimeInterval:300.0f
target:self
selector:@selector(updateMethod:)
userInfo:nil
repeats:YES];
And then create your update method:
- (void)updateMethod:(NSTimer *)theTimer {
// Your code goes here
}
You can use NSTimer to do this.
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html
Specifically, the
timerWithTimeInterval:target:selector:userInfo:repeats:
class method.
There is an easy way to do this, in you update method
-(void)update{
//Your update methods here
[self performSelector:@selector(update) withObject:nil afterDelay:300.0];
}
精彩评论