@interface someview:UIView{
NSTimer* timer;
}
@end
@implementation someview
-(void)dealloc{
NSLog(@"dealloc someview");
[timer invalidate];
timer = nil;
}
-(void)runTimer{
//
}
-(void)someMethod{
timer = [NSTimer timerWithTimeInterval:2.0f target:self selector:@selector(runTimer) userInfo:nil repeats:YES];
}
@end
釋放someview不會調用dealloc並且定時器繼續運行。NSTimer禁用UIView中的dealloc
如果我註釋掉「timer = [NSTimer schedule ....」部分,dealloc將被調用。這意味着我的代碼的所有其他部分正常工作,計時器是罪魁禍首。 runTimer方法是空的,這意味着它只是計時器與我混淆。
在上海華盈的的dealloc只叫,我把「[someview KillTimer函數]和[someview發佈],定時器得到無效,但dealloc中仍然不會被調用 – ssj 2011-04-14 22:42:35
然後其他的東西仍然保留視圖 – bbum 2011-04-14 23:03:43
不知道爲什麼我實施的killtimer方法沒有工作我第一次嘗試它..但它現在起作用 – ssj 2011-04-15 01:10:36