2012-04-27 16 views
1

在我的應用我有一個情況我編程方式更改tabBarController的選定索引這樣如何編程趕上改變tabBarController的setSelectedIndex

[self.tabBarController setSelectedIndex:0]; 

,並回到我的包含一個UITableView標籤」在這一點上我需要讓我的tableView 一些行動,我試圖用viewWillAppear中,並沒有到達那裏,我試圖使視圖代表這樣

@interface ThirdViewController : UITableViewController < UISearchBarDelegate,UINavigationControllerDelegate, UITabBarDelegate> 

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ 

它沒有工作

任何人都知道該怎麼做?

回答

2

我注意到,您的ThirdViewController類實現UITabBarDelegate,而tabBarController:didSelectViewController:其實UITabBarControllerDelegate協議的方法。

+0

tabBarController:didSelectViewController :僅在UITabBarController的ui事件(單擊)時被調用,並且在使用[self.tabBarController setSelectedIndex:0]時我沒有一個;我試過了,但它不起作用 – 2012-04-28 06:58:29

+0

爲什麼你接受這個答案,如果它不適合你? – yunas 2013-03-07 15:23:33

0

試試這個下面的代碼:

self.tabBarController.selectedIndex = 1; 

[self.tabBarController setSelectedIndex:1]; 

謝謝..!

UPDATE:

您可以tabBarcontroller viewDidLoad方法設置委託下面的代碼:

tabBarController.delegate=self; 
+0

這就是我現在要做的,我想在視圖中看到它跳到 – 2012-04-27 10:46:10

+0

好吧,現在我更新答案...! – Dinesh 2012-04-27 10:49:54

+0

我試過你的更新,它是工作,如果我點擊按鈕,但我使用[self.tabBarController setSelectedIndex:0];然後函數不叫 – 2012-04-27 15:33:21

0

對我來說,解決辦法是讓[控制器的alloc]初始化]和激活功能做的事情我需要在控制器IM移動到

+0

詳細說明這件事... – yunas 2013-03-07 15:24:13

0

我已經做了這個簡單的函數來選擇我的UITabBarController內的編程視圖控制器。

-(void)selectVCfromIndex:(int)index{ 

    self.selectedIndex = index; 
    [self tabBarController:self shouldSelectViewController:[self.viewControllers objectAtIndex:index]]; 

} 

在shoudSelectViewController協議我有特定的代碼,用於呈現視圖控制器和以這種方式,當凸片同時改變編程並通過用戶交互運行。