So I have a viewController
with a tableView
that is being presented from a tabBarController
. If the user taps the tabBarItem
for the view that is already being shown, I want the tableView
to scroll to the top. I have set the UITabBarControllerDelegate
to be the viewController
and then added the following method:
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if tabBarController.selectedIndex == 0 {
//scroll to the top!
}
}
The problem is that the tableView
scrolls to the top regardless of the current view. So I tried to add a second condition that makes sure that the currently displayed view is the correct one but nothing seemed to be correct.
TL;DR
How can I tell that the user is tapping on the tabBarItem
that is already selected?