타이머 시작/멈춤:
// Private Methods
@interface MyClass ()
{
NSTimer *_timer;
}
- (void)_timerFired:(NSTimer *)timer;
@end
@implementation MyClass
- (IBAction)startTimer:(id)sender {
if (!_timer) {
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0f
target:self
selector:@selector(_timerFired:)
userInfo:nil
repeats:YES];
}
}
- (IBAction)stopTimer:(id)sender {
if ([_timer isValid]) {
[_timer invalidate];
}
_timer = nil;
}
- (void)_timerFired:(NSTimer *)timer {
NSLog(@"ping");
}
https://stackoverflow.com/questions/12052914/how-can-i-start-and-stop-nstimer/12053057