我無法使NSTimer失效,他仍然繼續運行。無法使另一個類中的nstimer無效
在 類一個我有:
-(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;
...
}
然後乙級,開始與停止:
classAinst=[recordMachine alloc];
[classAinst startMachine]; //it starts here.
......
[classAinst stopMachine]; //it class the method to stop it,but the timer still ticks.
什麼可能導致此? 我需要爲計時器創建一個屬性嗎? class a正在從b拿着計時器,所以它應該停止它沒有?
你確定你只開始一次嗎? – Alexander
是的,我確定,已經檢查過。 – user1280535
@ user1280535只是爲了澄清,當你停止你的recordMachine時,「STOP THE MACHINE」被打印,但是「recordMachine」仍在打印,對不對? – janusbalatbat