2013-08-05 26 views
1

我有如下所示的項目結構。如何在點擊相應按鈕後轉到標籤欄控制器

enter image description here

在左邊我有MainViewController。我有兩個按鈕,分別是英語和阿拉伯語。我想要做的是當我點擊英文時,我想要去英文標籤欄控制器(HomeViewController)。

因此我寫的是

- (IBAction)langEnglish:(id)sender { 
    HomeViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:@"enghome"]; 
    [self.navigationController pushViewController:secondView animated:YES]; 
} 

這是工作完美,但我沒有看到標籤欄。

標籤欄從此丟失。

任何想法是什麼問題?


基本上我有什麼是視圖控制器作爲主控制器,並在點擊該控制器上的按鈕,標籤視圖控制器應該拿開...

+0

您顯示的代碼應該工作。在執行推送之前,請嘗試記錄secondView的類 - NSLog(@「%@」,[secondView class])。它給了什麼? – rdelmar

+0

@rdelmar:我得到的解決方案...我會很快發佈.. –

回答

1

我所做的是如下

- (IBAction)langEnglish:(id)sender { 
    EngTabViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:@"engtab"]; 
    [self.navigationController pushViewController:secondView animated:YES]; 
} 

EngTabViewController是的UITabBarController和我分配的ID標籤欄控制器...這就像魅力。

意味着不是viewcontorller,我用tabbarcontroller ...

1

轉到你的主要情節串連圖板,並選擇您的主視圖控制器。在頂部選擇編輯器 - >嵌入 - >導航欄。

編輯:如果這不起作用推到你的標籤欄,並使用此代碼:

self.tabBarController.selectedIndex = 1; 
+0

如果你看到圖像,我已經有mainviewcontroller之前的導航欄...關於'self.tabBarController.selectedIndex = 1;'它那裏...問題是我沒有看到標籤欄... –

+0

看到我的答案...我做到了... –

0

你不應該在一個UINavigationController推的UITabBarController。將其設置爲窗口的根視圖控制器,並按預期方式顯示選項卡欄。

+0

我明白,但首先屏幕應該是homeviewcontroller選擇語言..然後我會去與標籤欄控制器... ... –

+0

看到我的答案...我做到了... –