2011-10-22 59 views
3

我有一個UITableView,我想在單擊UITableView中的單元時切換到另一個選項卡。如何以編程方式切換到UITabBarController中的另一個選項卡?

我已經試過了,但它不工作

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

MainView *mainView = [[MainView alloc] initWithNibName:@"MainView" bundle:nil]; 
mainView.tabBarController.selectedIndex = 3; 

} 

回答

15

每次選擇一行時,您正在加載MainView的新副本。這些新副本不顯示在任何地方。您需要訪問您的主視圖的現有顯示實例的標籤欄控制器。也許這將工作:

self.tabBarController.selectedIndex = 3; 
1

是否檢查mainView.tabBarController不是零?

1
[self.tabBarController setSelectedIndex:2]; 
相關問題