Skip to content

Instantly share code, notes, and snippets.

@harrysummers
Last active May 11, 2018 22:58
Show Gist options
  • Select an option

  • Save harrysummers/954c1bae367a70281914ec357af97946 to your computer and use it in GitHub Desktop.

Select an option

Save harrysummers/954c1bae367a70281914ec357af97946 to your computer and use it in GitHub Desktop.
Scroll to top on tab bar controller pressed
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