The viewWillAppear method in VC has gone twice.

problem description

the login page of my app is a mode out of a VC app, log out, log in again, re-switch window.rootViewController

but found that the viewWillAppear method in the first child VC of tab has been walked twice

I found out the reason myself

the first pass is because I called dismissViewController
the second pass because I called appDelegate.window.rootViewController = tabVC;

.

but I don"t know how to solve this problem. I hope God will guide me

.

related codes

[self dismissViewControllerAnimated:YES completion: ^ {
AppDelegate appDelegate = (AppDelegate ) [[UIApplication sharedApplication] delegate];
appDelegate.window.rootViewController = tabVC;
}];

what result do you expect? What is the error message actually seen?

May.12,2022

Why does dismissViewController go to viewWillAppear? it's so strange that


based on the content, I guess you didn't destroy the loginVC when you popped up tabVC, and you created a new one when you logged in and redisplayed it successfully.

first time:
Click to log out and log in directly in tabVC present loginVC. At this point, dismiss loginVC will trigger the viewWillAppear of tabVC.
the second time:
tabVC should be newly created. Setting rootViewController at this time will trigger the viewWillAppear of the new tabVC. Because it is a vc, you think you have gone through it twice.

Menu