PDA

View Full Version : UITabBarItem Category giving error on Device | Debug ONLY!?!?




marcolara
Aug 22, 2008, 07:43 PM
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)
-(void)setImage:(UIImage*)image{
if(image == NULL){ //might be called with NULL argument
return;
}
_image = [image retain];
_selectedImage = [image retain];
}
@end


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.

-ML



kainjow
Aug 23, 2008, 01:44 PM
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).