2010-07-07 2 views

답변

9

타이머 개체에 대한 참조 만 유지하면됩니다. 그런 다음 충분히 해 냈을 때 무효화하십시오.

// ivars 
int loopCount; 
NSTimer *myTimer; 

// Method that calls your timer. 
- (void)doStuff { 
    loopCount++; 
    if (loopCount >= 10) { 
     [myTimer invalidate]; 
     myTimer = nil; 
    } else { 

     //do my stuff here... 

    } 
} 

// Method that kicks it all off 
- (IBAction)startDoingStuff { 
    myTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 
               target:self 
              selector:@selector(doStuff) 
              userInfo:nil 
               repeats:YES]; 
} 
관련 문제