Skip to content

Instantly share code, notes, and snippets.

@29satnam
Created March 9, 2018 07:49
Show Gist options
  • Save 29satnam/32527edba843518b092a1ae43aaafb3f to your computer and use it in GitHub Desktop.
Save 29satnam/32527edba843518b092a1ae43aaafb3f to your computer and use it in GitHub Desktop.
private var previousController: UINavigationController? = nil;
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
guard let navigationController = tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController else {
return
}
let canScrollToTop = navigationController == previousController
if let tableViewController = navigationController.topViewController as? ProfileTableViewController, canScrollToTop {
tableViewController.tableView.setContentOffset(.zero, animated: true)
}
previousController = navigationController
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment