- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
tabBarController = self.router.tabController;
for(UINavigationController* view in tabBarController.viewControllers) {
UIViewController* topView = view.topViewController;
if([topView isKindOfClass:[DiscussMainViewController class]]) {
viewController = (DiscussMainViewController*)view;
break;
} else if([topView isKindOfClass:[JobsMainViewController class]]) {
viewController = (JobsMainViewController*)view;
break;
} else if([topView isKindOfClass:[DailyListViewController class]]) {
viewController = (DailyListViewController*)view;
break;
} else if([topView isKindOfClass:[ProfileTableViewController class]]) {
viewController = (ProfileTableViewController*)view;
break;
}
}
if([viewController isEqual:tabBarController.selectedViewController]) {
if([viewController respondsToSelector:@selector(scrollToTop)]) {
[viewController performSelector:@selector(scrollToTop) withObject:nil];
}
}
}
然而,所有视图控制器中的scrollToTop函数都是那样的
- (void)scrollToTop {
[self.table setContentOffset:CGPointZero animated:YES];
}