Created
February 24, 2022 13:23
-
-
Save KrauserHuang/dfdc6af478023efc0bfd4cb58e8b2677 to your computer and use it in GitHub Desktop.
Pass data from one view controller to another one which both connect tabbar controller and navigation controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // self == TopPageNavigationController | |
| // use .selectedIndex to jump to second tabbar(means to ShopListViewController) | |
| self.tabBarController?.selectedIndex = 1 | |
| // use .selectedViewController to match your index, because ShopListViewController is tied with navigation controller | |
| // you need to down cast to the right navigation controller in order to find the controller you want(ShopListViewController) | |
| let shopNavigationController = self.tabBarController?.selectedViewController as? ShopNavigationController | |
| // to remove all the related view controllers from ShopNavigationController except itself | |
| shopNavigationController?.popToRootViewController(animated: false) | |
| if let shopListViewController = shopNavigationController?.viewControllers.compactMap({ $0 as? ShopListViewController }).first { | |
| // do property to change, and here you can pass data | |
| shopListViewController.channelPrice = channelPrice | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment