Last active
May 11, 2018 22:58
-
-
Save harrysummers/954c1bae367a70281914ec357af97946 to your computer and use it in GitHub Desktop.
Scroll to top on tab bar controller pressed
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
| func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) { | |
| let topIndex = IndexPath(row: 0, section: 0) | |
| if let navController = viewController as? UINavigationController, | |
| navController.childViewControllers.count > 0 { | |
| let childController = navController.childViewControllers[0] | |
| if let vc = childController as? AlbumsTableViewController { | |
| vc.tableView.scrollToRow(at: topIndex, at: .top, animated: true) | |
| } else if let vc = childController as? ArtistsTableViewController { | |
| vc.tableView.scrollToRow(at: topIndex, at: .top, animated: true) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment