現在、(ユーザーが作業している)同じタブをタップすると、アプリはそのタブの最初のページに移動します。
ユーザーが現在作業しているタブのタップイベントを無効にしたい。
ヒントはありますか?
現在、(ユーザーが作業している)同じタブをタップすると、アプリはそのタブの最初のページに移動します。
ユーザーが現在作業しているタブのタップイベントを無効にしたい。
ヒントはありますか?
tabBarController:shouldSelectViewController:
デリゲートメソッドを試しましたか?お役に立てば幸いです。
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
id currentViewController = tabBarController.selectedViewController;
return (viewController != currentViewController);
}
タブバーコントローラーのビューコントローラーがすべて の場合はUINavigationControllers
、このようにする必要があります。
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
id nextVC = [(UINavigationController *)viewController topViewController];
id currentVC = [(UINavigationController *)tabBarController.selectedViewController topViewController];
return (nextVC != currentVC);
}
Swift 4 の場合、デリゲート メソッドは次のようになります。
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
return viewController != tabBarController.selectedViewController
}
以下のように使用すると機能します
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
if(self.tabBarController.selectedIndex==[[self.tabBarController viewControllers] indexOfObject:viewController])
return NO;
else
return YES;
}