IOS 5: UITabBarItem setFinishedSelectedImage: withFinishedUnselectedImage: not working / ignored

According to Apple docs

I am trying to set up custom finished selected and unselected images on a UITabBarItem like this:

... DetailViewController *vc1 = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:nil]; UITabBarItem *vc1i = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemTopRated tag:100]; [vc1i setFinishedSelectedImage:[UIImage imageNamed:@"tab_bar_item_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_bar_item_normal.png"]]; [vc1 setTabBarItem:vc1i]; ... 

Basically what happens, the TabBar loads just fine, it just completely ignores the setting of the tab bar item.

I focus on iOS5 +

Images are transparent PNG 30x30 and exist in the project. I can’t understand what I’m looking at here, but there must be something!

This is called in the tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath , ala Ray Wenderlich tutorial

Does anyone have any ideas?

Thanks!

+1
source share
2 answers

The tab bar item is initialized using the method: initWithTabBarSystemItem:tag: But, as the documentation says:

This method returns the toolbar item provided by the system. The title and image properties of the returned item cannot be changed later.

You must initialize the tab bar item with initWithTitle:image:tag:

 UITabBarItem *vc1i = [[UITabBarItem alloc] initWithTitle:@"Top Rated" image:nil tag:100]; [vc1i setFinishedSelectedImage:[UIImage imageNamed:@"tab_bar_item_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_bar_item_normal.png"]]; 
+6
source

If you are trying to get the actual image to display in a UITabBar, use the following code.

 [yourTabBarItem setImage:[[UIImage imageNamed:@"more.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 

and if you want to display the image in the initial state for the selected one, use the following

 [yourTabBarItem setSelectedImage:[[UIImage imageNamed:@"more.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 

these two alternatives

 setFinishedSelectedImage: withFinishedUnselectedImage: 
+2
source

All Articles