Tap tab bar to scroll to top of UITableViewController

后端 未结 12 1041
面向向阳花
面向向阳花 2020-12-23 10:15

Tapping the tab bar icon for the current navigation controller already returns the user to the root view, but if they are scrolled way down, if they tap it again I want it t

12条回答
  •  北海茫月
    2020-12-23 10:33

    I have a collection view embedded in a navigation controller, in Swift this works.

    var previousController: UIViewController?
    
    func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {
        if previousController == viewController {
            if let navVC = viewController as? UINavigationController, vc = navVC.viewControllers.first as? UICollectionViewController {
                vc.collectionView?.setContentOffset(CGPointZero, animated: true)
            }
        }
        previousController = viewController;
    }
    

提交回复
热议问题