Tap tab bar to scroll to top of UITableViewController

后端 未结 12 1042
面向向阳花
面向向阳花 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:47

    You can use shouldSelect rather than didSelect, which would omit the need for an external variable to keep track of the previous view controller.

    - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
    {
        if ([viewController isEqual:self] && [tabBarController.selectedViewController isEqual:viewController]) {
            // Do custom stuff here
        }
        return YES;
    }
    

提交回复
热议问题