このシナリオでFirsViewControllerが破棄されない/解放された理由を理解できません。UINavigationControllerスタックからコントローラを削除します。
マイAppDelegate.m - FirstViewControllerがスタック
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
self.navigationController = [[UINavigationController alloc]init];
self.FirstViewController = [[FirstViewController alloc]
initWithNibName:@"FirstViewController"
bundle:[NSBundle mainBundle]];
[self.navigationController FirstViewController animated:YES];
にプッシュされFirstViewController.m
self.SecondViewController = [[SecondViewController alloc]
initWithNibName:@"SecondViewController"
bundle:[NSBundle mainBundle]];
self.SecondViewController.totalNumberOfPlayers = self.selectedRow;
[self.navigationController pushFadeViewController:self.SecondViewController];
[self.view removeFromSuperview];
-(void)dealloc
{
[SecondViewController release];
NSLog(@"SecondViewController released");
}
Iは、第一から第2のビューコントローラにアプリとスイッチを実行すると何のNSLog入力がありませんコンソールで。これにより、最初のView Controllerは破棄されず、そのメモリは解放されないと私は思います。
このような状況で[self.view removeFromSuperview]のように表示されないようです。
私の質問は、FirstControllerをリリース/破棄する方法です。それは、アプリケーションの残りの部分で使用されることはありません。
おかげで、ニック! 私には2つの質問があります。あなたが提案したコードを試しましたが、最初のView Controllerのdeallocメソッドは呼び出されません。また、そのコードを順番に使用できますか?私が使用することを意味する[navigationController setViewControllers:[NSArray arrayWithObject:thirdViewController] animated:YES]; theSecondViewControllerの[navigationController setViewControllers:[NSArray arrayWithObject:fourthViewController] animated:YES]; 3番目のビューコントローラなど – Profo
完了したらself.FirstViewControllerプロパティをnilに設定する必要があります。それ以外の場合は解放されません。 setViewControllers:メソッドを好きなだけ何度でも使用できますが、pushViewController:を使用して次のビューを表示しない限り、popViewController:メソッドを使用して前のビューに戻ることはできません。 –
私は実際には、FirstViewControllerをプロパティに格納しないことをお勧めします。関数内でローカル変数を使用して作成し、ナビゲーションコントローラにプッシュし、ローカル変数を解放します。 navigationControllerはそれが表示されている間はそれを保持しているので、アプリケーションデリゲートのプロパティに格納する必要はありません。 –