Skip to content

Instantly share code, notes, and snippets.

@KrauserHuang
Created February 24, 2022 13:23
Show Gist options
  • Select an option

  • Save KrauserHuang/dfdc6af478023efc0bfd4cb58e8b2677 to your computer and use it in GitHub Desktop.

Select an option

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
// 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