一般大多數(shù)情況下,這些方法都是由系統(tǒng)直接調(diào)用的,不會(huì)遇到手動(dòng)調(diào)用的場景;
但是在一些特殊場景下,例如父子視圖控制器嵌套,UIWindow嵌套視圖控制器時(shí)候,某些被嵌套的控制器在一些場景下不會(huì)自動(dòng)觸發(fā)上述系統(tǒng)方法.
直接調(diào)用編譯沒有問題,但是在運(yùn)行時(shí),編譯器會(huì)在控制臺輸出類似警告
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>
根據(jù)提示可以知道可以使用
-beginAppearanceTransition:animated: 和 -endAppearanceTransition: 驅(qū)動(dòng)系統(tǒng)用自己去調(diào)用viewDidDAppear 或者viewDidDisappear 等相關(guān)方法
開發(fā)中,當(dāng)有父子ViewController嵌套過程中,想要更新子的viewController生命周期方法來更新子viewController的UI時(shí)候,可以
讓子控制器 直接調(diào)用上面兩個(gè)方法