I have a subclass of UINavigationBar class. In viewDidLoad i have:
- (void)viewDidLoad
{
[super viewDidLoad];
UINavigationBar *bar = [[UINavigationBar alloc] init];
NSString* path = [[NSBundle mainBundle] pathForResource:@"topbanner" ofType:@"png" inDirectory:@"assets"];
NSData *data = [NSData dataWithContentsOfFile:path];
UIImage *image = [UIImage imageWithData:data];
[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; //crash here!
[self.view addSubview:bar];
}
And i call it from my tableView. When i run on simulator everything is fine, when i try to run on the device app crash. I have an error:
+[UINavigationBar appearance]: unrecognized selector sent to class 0x3e3fe490
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UINavigationBar appearance]: unrecognized selector sent to class 0x3e3fe490'
Why?
EDIT:
my topbanner file i have in blue directory folder in Xcode. In emulator everything looks fine.
EDIT2:
Of course, when i remove this line of code in my device my app looks good to, but there is no image on navigationbar (oc).
The
appearancemethod is new to iOS 5.0. You are probably using the simulator with iOS 5.0, but your device might use a lower iOS version.It is better to check with respondsToSelector before calling it to modify the appearance using this method.
From the UINavigationBar documentation:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationBar_Class/Reference/UINavigationBar.html