문제

I would like to know how to make the UITabBarItem be highlighted when I choose to do so in the program. Is this possible?

THanks

도움이 되었습니까?

해결책

You can change which tab is selected -- which also changes the highlight -- easily:

tabcontroller.selectedIndex = youNewIndexHere;

If your tabcontroller is in the app delegate (which is the case if you used the tab bar application template when you created your project) it would look something like this:

ProjectNameAppDelegate *appDelegate = (ProjectNameAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabcontroller].selectedIndex = youNewIndexHere;

다른 팁

tabbar works if you know the index and write it like this:

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];

I've got a UITabBar, created in IB but without a TabBarController. In my awakeFromNib I just initialise it to the first item like this:

[self.tabBar setSelectedItem:[[self.tabBar items] objectAtIndex:0]];

Don't forget, the UITabBarDelegate didSelectItem does not get called in this case.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top