我不能使 NSTimer 无效,他会继续运行。
在A 类我有:
-(void)startMachine
{
NSLog(@"START THE MACHINE " );
doesOn=1;
machineClock=[NSTimer scheduledTimerWithTimeInterval:0.05
target:self
selector:@selector(recordMachine:)
userInfo:nil
repeats:YES];
....//machineClock is on the .h file in interface
}
-(void)recordMachine:(NSTimer*)timer
{
NSLog(@"recordMachine");
...
-(void)stopMachine
{
NSLog(@"STOP THE MACHINE !! " );
[machineClock invalidate];
machineClock=nil;
...
}
然后在b 类中,开始和停止它:
classAinst=[recordMachine alloc];
[classAinst startMachine]; //it starts here.
......
[classAinst stopMachine]; //it class the method to stop it,but the timer still ticks.
什么可能导致这个?我需要为计时器创建一个属性吗?a 类正在持有 b 的计时器,所以它应该停止它吗?