UITabBarItem Category giving error on Device | Debug ONLY!?!?

Discussion in 'iOS Programming' started by marcolara, Aug 22, 2008.

  1. marcolara macrumors newbie

    Aug 15, 2008
    Hello guys! I have an issue that is puzzling me. I've created a category for UITabBarItem and it looks like this:

    @implementation UITabBarItem (UITabBarItemCategory)
    	if(image == NULL){ //might be called with NULL argument
    	_image = [image retain];
    	_selectedImage = [image retain];
    And here is my implementation in my ViewController subclass:

    #import "MainScreenViewController.h"
    #import "UITabBarItemCategory.h"
    @implementation MainScreenViewController
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    	if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    		// Initialization code
    		self.title = NSLocalizedString(@"main_tab_title","Main screen tab button");
    		[self.tabBarItem setImage:[UIImage imageNamed:@"TabBarItemMain.png"]];
    	return self;
    The intention of this is to customize the images displayed in the UITabBarController because the blue chrome color don't fit inside my design. It works like a champ in the Simulator however, when I try to run this in my iPhone device using the "Device|Debug" method, I get the following compilation error:

    "_OBJC_IVAR_$_UITabBarItem._image", referenced from:
    _OBJC_IVAR_$_UITabBarItem._image$non_lazy_ptr in UICategory.o
    "_OBJC_IVAR_$_UITabBarItem._selectedImage", referenced from:
    _OBJC_IVAR_$_UITabBarItem._selectedImage$non_lazy_ptr in UICategory.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    Build failed (2 errors)
    Could this be an Xcode bug? Am I doing something wrong?

    Conceptually, I should be able to access these private variables because I'm extending UITabBarItem.

    The other option will be to subclass the UITabBarItem and use it's drawRect method, however I don't know how to init the object because it's managed by a ViewController.

    Any tips and suggestions will be highly appreciated.

  2. kainjow Moderator emeritus


    Jun 15, 2000
    My only suggestion would be to redesign your UI to match the iPhone, not the other way around. If you want custom UI like this write your own tab view (wouldn't be too hard).

Share This Page