Showing posts with label How to use NSTimer class. Show all posts
Showing posts with label How to use NSTimer class. Show all posts

Tuesday, May 10, 2011

How to use NSTimer class

A simple example code showing how to use NSTimer class to schedule works.
NSTimer is very useful to do something repeatedly for some period of time.

// Method for timer to callback.
    - (void) handleTimer: (NSTimer *) timer
    {
      // Your work here (periodic work)
    }


// Create a NSTimer object to call above callback method.
//

    NSTimer *timer; 
    timer = [NSTimer scheduledTimerWithTimeInterval: 0.03f target: self selector: @selector(handleTimer:)

  userInfo: nil repeats: YES];

// Dismiss timer when you are done with it.
//
   [tmier invalidate];