2012-04-07 9 views

答えて

13

あなたはtabBarController試してみました:shouldSelectViewController:デリゲートメソッドを?私はそれがあなたを助けることを望む。

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { 

    id currentViewController = tabBarController.selectedViewController; 
    return (viewController != currentViewController); 
} 

タブバーコントローラのすべてのビューコントローラがUINavigationControllerの場合は、このようにする必要があります。

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { 

    id nextVC = [(UINavigationController *)viewController topViewController]; 
    id currentVC = [(UINavigationController *)tabBarController.selectedViewController topViewController]; 
    return (nextVC != currentVC); 
} 
+0

に動作します。 – viral

+0

私の更新された答えを見てください。 – EmptyStack

+0

はい、すべてのVCは「UINavigationControllers」です。 '(UINavigationController *)'の型変換のための特別な理由、または単に良いプログラミング実践のためです。それもなくても動作します。 – viral

0

それ以下のように使用することは、私はその方法を見つけましたが、どのようなコードがそれに行かなければならない...、私はわからないということ

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController 
    { 
     if(self.tabBarController.selectedIndex==[[self.tabBarController viewControllers] indexOfObject:viewController]) 
      return NO; 
     else 
      return YES; 
    } 
+0

if-elseステートメントのelse部分は必要ありません。 NOを返した場合、YESを返すことはできません。 – CodaFi

関連する問題