2010-01-26 82 views
0

我創建了一個的UITabBarController這樣的:爲什麼我的UITabBarController是空的?

InfoViewController *iVC = [[InfoViewController alloc] init]; 
self.infoViewController = iVC; // retain property 

UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:0]; 
self.infoViewController.tabBarItem = tabBarItem; 





UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:myVC]; 
self.navigationController = nc; 

UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostRecent tag:1]; 
self.navigationController.tabBarItem = tabBarItem; 






UITabBarController *tbc = [[UITabBarController alloc] init]; 

NSArray* controllers = [NSArray arrayWithObjects:self.infoViewController, self.navigationController, nil]; 

self.tabBarController = tbc; // retain property! 

self.tabBarController.viewControllers =控制器; [tbc release];

問題:我在底部看到一個黑色的標籤欄和一個白色的內容區域。數組中的第一個視圖控制器具有紅色背景色。所以它應該顯示爲紅色。

選項卡欄不顯示任何項目,它是空的。

可能是什麼問題?我不使用nib文件...沒有警告,沒有錯誤,沒有記錄到控制檯。只需清空選項卡欄。

回答

1

你不丟失:

self.tabBarController.viewControllers = controllers; 

編輯:

比好其他的我沒有看到附帶的代碼是錯誤的東西,所以這使我覺得這事否則一定是錯的。幾個選項:

  1. 你確定self.tabBarController指向任何東西(不是零)?
  2. 你確定它指向你看到的同一個UITabController嗎?
  3. 您確定您創建的控制器是否已正確創建?嘗試顯示它們,無論tabBar與

    [self.tabBarController presentModalViewController:iVC animated:YES];

  4. 是從NIB創建的UITabController嗎?如果在initWithNibName或awakeFromNib上放置NSLog以確保它在代碼之前被調用,並且不會在代碼之後被再次調用。

開始與這些如果沒有顯示出任何跡象表明,別的東西是錯誤的,我能想到的一些事情去嘗試。

+0

對,我忘了複製並粘貼到這裏。但這不是原因。 – openfrog 2010-01-26 16:32:26

+0

看到我更新的答案 – 2010-01-26 17:16:41