[英]Disable tap on current Tab (UITabBarController) iPhone App
Currently, Tapping on the same Tab (in which user is working), The App moves to the very first page of that Tab.目前,点击同一个选项卡(用户正在工作的选项卡),应用程序将移动到该选项卡的第一页。
I want to disable the tap event on the Tab in which user is working currently.我想禁用用户当前正在使用的选项卡上的点击事件。
Any Hint?任何提示?
You tried tabBarController:shouldSelectViewController:
delegate method?您尝试过
tabBarController:shouldSelectViewController:
委托方法吗? I hope that should help you.我希望这对你有帮助。
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
id currentViewController = tabBarController.selectedViewController;
return (viewController != currentViewController);
}
If all the view controllers of the tab bar controller are UINavigationControllers
, you should do it like this.如果标签栏 controller 的所有视图控制器都是
UINavigationControllers
,你应该这样做。
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
id nextVC = [(UINavigationController *)viewController topViewController];
id currentVC = [(UINavigationController *)tabBarController.selectedViewController topViewController];
return (nextVC != currentVC);
}
For Swift 4 the delegate method looks like this:对于 Swift 4,委托方法如下所示:
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
return viewController != tabBarController.selectedViewController
}
use like below it will work像下面这样使用它会起作用
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
if(self.tabBarController.selectedIndex==[[self.tabBarController viewControllers] indexOfObject:viewController])
return NO;
else
return YES;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.