点击选定的标签时,我遇到了一些麻烦,使得桌面视图显示在顶部。我正在使用自定义TabBarViewController,我在里面使用以下函数:
- (void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
{
static UIViewController *previousController = nil;
if (previousController == viewController) {
// the same tab was tapped a second time
if ([viewController respondsToSelector:@selector(scrollToTop)]) {
[viewController scrollToTop];
}
}
previousController = viewController;
}
我也遇到以下错误:
No visible @interface for 'UIViewController' declares the selector 'scrollToTop'
我想知道如何解决这个问题?如果您需要更多信息,请告诉我。这一直困扰我一周!
谢谢大家!!
答案 0 :(得分:0)
标签栏控制器的视图控制器是否有点像UINavigationController?也许你应该这样做:
- (void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
{
static UIViewController *previousController = nil;
if ([viewController isKindOfClass:[UINavigationController class]]) {
if (previousController == ((UINavigationController *)viewController).viewControllers.firstObject) {
// the same tab was tapped a second time
if ([viewController respondsToSelector:@selector(scrollToTop)]) {
[viewController scrollToTop];
}
}
previousController = ((UINavigationController *)viewController).viewControllers.firstObject;
} else {
previousController = viewController;
}
}