Tom February 2016

No visible interface for UITabBarItem when trying to set selectedImage

I've seen that you can add a selectedImage as well as an image for a UITabBarItem, so I amended a Cordova plugin to add that:

UIImage *tabIcon = [UIImage imageNamed:imageName];
UIImage *selectedTabIcon = [UIImage imageNamed:selectedImage];
tabIcon = [tabIcon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
selectedTabIcon = [selectedTabIcon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item = [[UITabBarItem alloc] initWithTitle:title image:tabIcon tag:tag selectedImage:selectedTabIcon];

with the selectedImage variable being a string passed in by the plugin here:

  NSString  *name      = [arguments objectAtIndex:0];
  NSString  *title     = [arguments objectAtIndex:1];
  NSString  *imageName = [arguments objectAtIndex:2];
  NSString *selectedImage = [arguments objectAtIndex:3];
  int tag              = [[arguments objectAtIndex:3] intValue];

However when I try to compile this I get the following error:

/Users/tomchambers/work/cordova-ios-tab-bar/src/ios/CDVTabBar.m:266:34: error: no visible @interface for 'UITabBarItem' declares the selector 'initWithTitle:image:tag:selectedImage:' item = [[UITabBarItem alloc] initWithTitle:title image:tabIcon tag:tag selectedImage:sel... ~~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.


I am not experienced with objective C, so I think it might be something simple I'm missing here.

When using different method (images definitely exist):

  UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"random" image:[UIImage imageNamed:@"www/assets/images/tab-bar-icons/ic_mail_outline.png"] selectedImage:[UIImage imageNamed:@"www/assets/images/tab-bar-icons/ic_mail_outline.png"]];

2016-02-08 11:48:31.367        


Shehzad Ali February 2016

The method you have used to instantiate TabBarItem doesn't exist. You must use any one of them:

UITabBarItem * item = [[UITabBarItem alloc] initWithTitle:@"title" image:[UIImage imageNamed:@"image.png"] tag:1];


UITabBarItem *item1 = [[UITabBarItem alloc] initWithTitle:@"title" image:[UIImage imageNamed:@"image.png"] selectedImage:[UIImage imageNamed:@"selectedImage.png"]]; 

Post Status

Asked in February 2016
Viewed 1,089 times
Voted 6
Answered 1 times


Leave an answer