Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call method every 5 minutes in my UIView

I want to call a certain method in my UIView code say every 5 minutes - how do I accomplish that?

like image 938
Slee Avatar asked Dec 10 '22 07:12

Slee


2 Answers

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
}
like image 52
faroligo Avatar answered Dec 11 '22 20:12

faroligo


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.

like image 29
Joshua Smith Avatar answered Dec 11 '22 19:12

Joshua Smith