UITabBarController.selectedIndex does not change the tabBar icon?
When using UITabBarController
in my app, I cannot get the first item in it's TabBar
to be selected开发者_StackOverflow (i.e. blue color). It just stays black and gray.
Is there another method to activate a certain item in the TabBar? I'm using:
self.tabController.selectedIndex = 0;
(For matter of interested, this is all instantiated in the AppDelegate as the delegate is handling a welcome view) which is, once dismissed removed from screen and the UITabController.view
is taking over.
Update:
In the Main App Delegate, I use this code to show the tabController and set the index:
#pragma mark - Click handlers
- (void) startApp:(id)sender {
[UIView transitionFromView:self.welcomeView
toView:self.tabController.view
duration:0
options:UIViewAnimationOptionTransitionFlipFromRight
completion:nil];
self.tabController.selectedIndex = 0;
}
self.tabController
is not null, else I would not be able to see the view on the screen.
This was happening to me as well. I finally realized it came down to the way I was constructing the UITabBarItems for my tab views. Being unable to find any examples of the proper way to provide the images for the tabs, I had settled on overridding tabBarItem in each of my views to return a UITabBarItem I had constructed myself. This appeared to load the icons properly but wouldn't change the higlight when I changed the selectedIndex programmatically.
Finally last night I found code like this in the init method of the child view controllers in an iOS book on Google Books:
UIImage *anImage = [UIImage imageNamed:@"foo"];
self.tabBarItem.image = anImage;
Setting up the tab bar items this way fixed the problem with highlighting the correct button when switching tabs programmatically for me.
Is self.tabController nil?
NSLog(@" my tab controller is 0x%x", self.tabController);
精彩评论