1

我有一個UITabBarController,其中有幾個標籤欄項目。第一個標籤欄項目有一個名爲A的視圖,它有一個名爲Click的按鈕。當我點擊那個按鈕時,視圖將導航到另一個視圖。 (由於這個標籤有一個UINavigationController,視圖將會得到一個返回按鈕)。將焦點設置爲UITabBarItem

現在這個視圖將有一個按鈕,當我點擊它時,我應該導航到第二個TabItem。 (含義UITabBarItem應設置焦點,並且不應該有一個後退按鈕(如在導航控制器))

注:

當用戶點擊該按鈕時,我用下面的代碼來導航到另一個UITabBarItem的另一個視圖。然後,第二個標籤欄項目未設置爲對焦狀態,並且還可以看到導航控制器的後退按鈕。

SelectSiteViewController *siteViewController = 
[[SelectSiteViewController alloc] initWithNibName:@"SelectSiteViewController" 
              bundle:nil]; 
[self.navigationController pushViewController:siteViewController 
            animated:YES]; 

希望我明確提出了我的問題。我如何編碼?

+1

您正在將視圖控制器**推到**導航堆棧上......後退按鈕在那裏讓用戶回來。但是你沒有改變活動標籤欄項目,所以沒有焦點,沒有第二個視圖控制器和後退按鈕。您可能正在尋找更改'UITabBarController'的[selectedViewController]屬性(http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html)。 – 2011-12-17 16:44:32

+0

我是通過Google搜索找到的;這是正確的'self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:2];' – Illep 2011-12-17 17:13:04

+0

它應該...如果'2'是你想要的索引..你測試了嗎? – 2011-12-17 17:13:55

回答

3

據我所知,您希望從導航任務中刪除當前的視圖控制器並選擇標籤欄控制器中的第二個選項卡。

UINavigationController *navigationController = self.navigationController; 
[navigationController popToRootViewControllerAnimated:NO]; 
[navigationController.tabBarController setSelectedIndex:1]; 
1
[myTabBarController setSelectedIndex:1]; 
+0

這隻會將焦點設置到tabbaritem,我應該怎樣做導航欄中的後退按鈕? – Illep 2011-12-17 17:10:42

+0

[self.navigationItem setBackBarButtonItem:nil]; – 2011-12-17 18:58:46