请帮我理解navigationController的奥秘。我有一个从 didFinishLaunchingWithOptions 调用的 HomeViewController。从 HomeViewController 用户按下一个按钮,我的代码是
-(IBAction)showMap:(id)sender
{
MapViewController *mapViewController = Nil;
mapViewController = [[MapViewController alloc] initWithNibName:@"MapView-iPad" bundle:nil];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.navigationController pushViewController:mapViewController animated:YES];
}
当用户想从 MapViewController 返回时,我使用代码
-(IBAction)goBackToHome:(id)sender
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.navigationController popViewControllerAnimated:YES];
}
我的印象是,一旦我离开 MapViewController,我的所有资源都会与 MapViewController 相关联。为了验证我是否将此代码放在 MapViewController 的 initWithNibName 中。
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(printMessage) userInfo:nil repeats:YES];
}
return self;
}
-(void) printMessage
{
NSLog(@"I am inside Map View Controller");
}
令我惊讶的是,即使在弹出 MapViewController 之后,printMessage 仍然继续。请帮助我了解发生了什么以及为什么 MapViewController 仍在运行。有什么方法可以验证 MapViewController 是否已释放?