iOS UIViewController各种情况下生命周期方法调用顺序

UINavigationControllerviewControllerA通过pushViewController:animated:跳转到viewControllerB

- [viewControllerB viewDidLoad]
- [viewControllerA viewWillDisappear:]
- [viewControllerB viewWillAppear:]
- [viewControllerA viewDidDisappear:]
- [viewControllerB viewDidAppear:]

Storyboard下创建的UITabBarController

下面使用tabBarController表示UITabBarController、subViewController0表示UITabBarController的第一个子控制器,subViewController1表示UITabBarController第二个子控制器
调用顺序如下

-[subViewController0 initWithCoder:]
-[subViewController1 initWithCoder:]
-[tabBarController initWithCoder:]
-[tabBarController awakeFromNib]
-[subViewController0 awakeFromNib]
-[subViewController1 awakeFromNib]
-[tabBarController viewDidLoad]
-[subViewController0 viewDidLoad]
-[subViewController0 viewWillAppear:]
-[tabBarController viewWillAppear:]
-[subViewController0 viewDidAppear:]
-[tabBarController viewDidAppear:]

点击TabBarItem切换子控制器时调用顺序如下:

-[subViewController1 viewDidLoad]
-[subViewController1 viewWillAppear:]
-[subViewController0 viewWillDisappear:]
-[subViewController0 viewDidDisappear:]
-[subViewController1 viewDidAppear:]

你可能感兴趣的:(iOS UIViewController各种情况下生命周期方法调用顺序)