0
A
回答
3
您可以更改選項卡中選擇 - 這也改變了重頭戲 - 輕鬆:
tabcontroller.selectedIndex = youNewIndexHere;
如果您tabcontroller是在應用程序的委託(這是,如果你使用的情況下標籤欄應用程序模板,當您創建項目),它會是這個樣子:
ProjectNameAppDelegate *appDelegate = (ProjectNameAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabcontroller].selectedIndex = youNewIndexHere;
0
的TabBar工作,如果你知道這個指數,它這樣寫:
NSMutableArray *item [[NSMutableArray alloc] init];
[items addObject: [[[UITabBarItem alloc] initAsULike] autorelease]; <--- init as you like here
...
[tabBar setItems:items animated:FALSE];
tabBar.selectedItem = [items objectAtIndex: your_index]; <--- write your index here
[items release];
+0
和ofc將tabbar添加到視圖並釋放它! – chikuba 2011-08-31 10:09:16
0
我有一個UITabBar,在IB中創建但沒有TabBarController。在我awakeFromNib我只是將其初始化像這樣的第一個項目:
[self.tabBar setSelectedItem:[[self.tabBar items] objectAtIndex:0]];
不要忘了,UITabBarDelegate didSelectItem不會被調用在這種情況下。
謝謝!在selectedIndex的情況下,這是什麼?對象ID?或標籤? – Lilz 2010-11-05 09:16:54
新選項卡,第一個選項卡爲0,第二個選項爲1,等等(如果這適用於您,請檢查我的答案旁邊的複選標記。) – 2010-11-05 09:24:52
我沒有tabBarController而是UITabBar,它工作嗎請以同樣的方式? – Lilz 2010-11-05 09:40:19