2010-08-10 70 views

回答

1

使用UITabBar的items屬性,如:

if([[myTabBar items] indexOfObject:myTabBarItem] == 0) 
{ 
    UITabBarItem* theItem = [[myTabBar items] objectAtIndex:0]; 

    if([theItem.title isEqualToString:@"Hello"]) 
    { 
    // it's in position 0 and has title "Hello" 
    } 
} 
+3

我不會推薦看標題,特別是如果你使用字符串本地化的東西。相反,將標籤用於此目的,並定義一系列代表選項卡的整型值,定義一些常量以使您的代碼在將來回到代碼時更具可讀性,並在代碼上進行比較。 – jer 2010-08-10 23:40:32

+0

完全同意。 – 2010-08-10 23:44:36

0

uitabbaritem繼承自定義標籤和標題屬性的uibaritem。

2

我寧願讓tabBar項目陣列上使用indexOfObject項目的指標:

NSUInteger index = [tabBar.items indexOfObject:item];