2016-04-04 19 views
2

請幫我找到解決方案案例:IOS - 拍了拍TabBarItem,檢查變量,以顯示相應的ViewController

UITabBarController在故事板。當我點擊TabBarItem(索引1)時,我應該檢查變量(int)'ShowVC'以顯示相應的視圖控制器。 E.g:

switch (ShowVC) { 
      case 1: 
       showViewController1; 
       break; 
      case 2: 
       showViewController2; 
       break; 
      case 3: 
       showViewController3; 
       break; 
      default: 
       break; 
     } 

那麼,什麼是解決呢?

我在哪裏可以添加檢查方法來顯示視圖控制器時點擊TabBarItem?

回答

0
+0

不,你不明白我的問題。您點擊標籤欄項目1,您檢查並顯示VC1或VC2或VC3取決於變量'ShowVC'。不要標籤欄項目1顯示VC1,標籤欄項目2顯示VC2,... – QuocTV

+0

更詳細地描述你想要做什麼。 –

+0

我需要檢查用戶的權限以顯示相應的視圖控制器 – QuocTV

0

我明白了什麼是你需要得到通知被點擊或螺紋的標籤時。

在AppDelegate中的didFinishLaunchingWithOptions

UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController; 
[tabBar setDelegate:self]; 

現在didSelectViewController你可以寫你的邏輯或條件什麼來顯示。

- (void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    //Write your logic here 
    tabBarController.selectedViewController = yourNewController; 
}