[英]How to call a method when an iOS UINavigationController has been popped?
[英]UINavigationController has to call method when updates view with a new ViewController
我有一個 UINavigationControllerSubclass。 當視圖控制器彈出到一些新的視圖控制器時(通過navigationController.popViewController
、 navigationController.popToRootViewController
甚至manually sliding from left to right
)
我需要在我的導航控制器內部調用:
viewController.newTopViewController.updateBackButtonTitle()
實現這一目標的最佳方法是什么?
這樣做的一種方法如下:
class CustomNavigationController: UINavigationController {
override func popToRootViewController(animated: Bool) -> [UIViewController]? {
shouldUpdateBackButtonTitle()
return super.popToRootViewController(animated: animated)
}
override func popViewController(animated: Bool) -> UIViewController? {
shouldUpdateBackButtonTitle()
return super.popViewController(animated: animated)
}
private func shouldUpdateBackButtonTitle() {
viewController.newTopViewController.updateBackButtonTitle()
}
}
當您返回 viewController 時,請調用此 viewWillAppear 方法。 在該函數中,您可以檢查您的 rootviewController,然后您可以調用您的
updateBackbuttonTitle()< 函數。
您可以使用 viewWillAppear 方法,並輕松更新 UI 控件 super.viewWillAppear(animated)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.