the key window's rootViewController is a login ViewController。In the login viewController, i will modal or push other viewControllers. When login successfully, it would switch the rootViewController to viewController C. I find the login viewController's dealloc method is not fired.
I found same question similarity my question, but not resolve my question.
The test demo code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
ViewControllerA *vc = [[ViewControllerA alloc] init];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
In the viewControllerA(vcA), i modal viewControllerB(vcB)
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
ViewControllerB *vcB = [[ViewControllerB alloc] init];
[self presentViewController:vcB animated:YES completion: nil];
}
In the vcB, i switch the key window's rootViewController to vcC
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
// [keyWindow.rootViewController removeFromParentViewController];
// keyWindow.rootViewController = nil;
keyWindow.rootViewController = [ViewControllerC new];
you will find, the dealloc method of vcA will not fire.
If i dismiss the vcB when switch the rootViewController, it would be good
[self dismissViewControllerAnimated:NO completion: nil];
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
// [keyWindow.rootViewController removeFromParentViewController]; // 无效
// keyWindow.rootViewController = nil; // 无效
keyWindow.rootViewController = [ViewControllerC new];
so, what should i do to dealloc vcA?
Here is my test demo enter link description here