2013-11-23 46 views
0

我正在做一個聯繫人應用程序,所以在一個頁面中,如果沒有聯繫人,我需要它不會打開,所以我設置了一個if viewWillAppear中。一切工作差不多大:當我選擇這個選項卡,警報告訴我,有沒有接觸,並將該選項卡中的變化,但視圖不 [在這裏輸入的形象描述] [1]以編程方式更改TabBar不工作(self.tabBarController.selectedIndex = tabBarIndex :)

https://cloudup.com/cZDl8XW1aun(截圖聯繫! )

我做了一個測試,如果我把改變tabBar代碼在除了ViewDidLoad或ViewWillAppear之外的其他地方它的作品,但我不想這樣。

對不起,我的英語不好,或者如果我做了一個白癡的錯誤,我是一個noob。

if (contacts.count == 0) 
{ 
    UIAlertView *alerta = [[UIAlertView alloc] initWithTitle:@"Attentione" message:@"You doesn't have any contacts added" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

    [alerta show]; 

    self.tabBarController.selectedIndex = 1; 

} 
else 
{ 

... 。 .. .. 。 }

回答

0

一定要調用代碼從viewDidLoad方法設置所選指數:

- (void)viewDidload 
{ 
    [super viewDidLoad]; 

    // Call from viewDidload 
    [self.tabBarController setSelectedIndex:1]; 
} 
相關問題