我有一个带有UIView的XIB。 此UIView与UIView - Page1的自定义类关联(在IB中)。 文件的所有者是MainMenuController(当然是UIViewController)。 当init控制器使用“initWithNibName”并将其添加到navController.viewControllers中时,我使用此XIB。当我使用“layoutSubviews”或“didMoveToSuperview”时,请勿调用“dealloc”方法
在Page1.m我写:
- (void)didMoveToSuperview
{
NSLog(@"Page 1 did move to superview");
mainTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(refreshDateAndTime) userInfo:nil repeats:YES];
}
-(void) refreshDateAndTime {
NSLog(@"second");
}
- (void)dealloc
{
NSLog(@"Page1 dealloc called");
[mainTimer invalidate];
mainTimer = nil;
[mainTimer release];
[super dealloc];
}
当我启动计时器“mainTimer”由此代码,方法“的dealloc”不叫和对象不从存储器和计时器正在运行卸载。 如果我在“didMoveToSuperview”块中调用了dealloc块中的行,并且全部都正常。 为什么?
感谢您的帮助! – 2011-05-04 11:24:38