0
@interface ClassWithTimer : NSObject {
}
-(void) startTimer;
-(void) stopTimer;
@end
@implementation ClassWithTimer
NSTimer *up;
-(void) startTimer{
up = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(doSomething) userInfo:nil repeats:YES];
-(void) stopTimer{
[up invalidate];
}
- (void) doSomething{}
@end
- (IBAction)startTimers:(id)sender {
timer1 = [[ClassWithTimer alloc] initWithName:@"time1"];
timer2 = [[ClassWithTimer alloc] initWithName:@"time2"];
[timer1 startTimer];
[timer2 startTimer];
[timer1 stopTimer];
[timer2 stopTimer];
}
當我停止計時器我看到TIMER1同爲Timer2和在無效的方法拋出異常[定時器2 stopTimer]因爲這個對象此時失效。
我知道這是iOS政策,但我找不到這方面的文檔。