一般大多数情况下,这些方法都是由系统直接调用的,不会遇到手动调用的场景;
但是在一些特殊场景下,例如父子视图控制器嵌套,UIWindow嵌套视图控制器时候,某些被嵌套的控制器在一些场景下不会自动触发上述系统方法.
直接调用编译没有问题,但是在运行时,编译器会在控制台输出类似警告
Calling -viewDidDisappear: directly on a view controller is not supported, and may result in out-of-order callbacks and other inconsistent behavior. Use the -beginAppearanceTransition:animated: and -endAppearanceTransition APIs on UIViewController to manually drive appearance callbacks instead. Make a symbolic breakpoint at UIViewControllerAlertForAppearanceCallbackMisuse to catch this in the debugger. View controller: <QYHomeViewController: 0x102835770>
Calling -viewDidAppear: directly on a view controller is not supported, and may result in out-of-order callbacks and other inconsistent behavior. Use the -beginAppearanceTransition:animated: and -endAppearanceTransition APIs on UIViewController to manually drive appearance callbacks instead. Make a symbolic breakpoint at UIViewControllerAlertForAppearanceCallbackMisuse to catch this in the debugger. View controller: <QYNavigationController: 0x10701e000>
根据提示可以知道可以使用
-beginAppearanceTransition:animated: 和 -endAppearanceTransition: 驱动系统用自己去调用viewDidDAppear 或者viewDidDisappear 等相关方法
开发中,当有父子ViewController嵌套过程中,想要更新子的viewController生命周期方法来更新子viewController的UI时候,可以
让子控制器 直接调用上面两个方法