I try to assign an image loaded via
[UIImage imageWithData: [NSData dataWithContentsOfURL:imageUrl]];
to my navigationbar. Here is what i have:
//Loading Image from Url and adding it to navigationbar
NSString *urlString = [NSString stringWithFormat:@"http://someurl.com/%@.gif",imageId];
NSURL *imageUrl = [NSURL URLWithString:urlString];
UIImage *myImage = [UIImage imageWithData: [NSData dataWithContentsOfURL:imageUrl]];
UIButton* button = (UIButton *) myImage;
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.rightBarButtonItem = buttonItem;
This works as long as i take a local image and allocate the image view like this:
UIButton* button = (UIButton *) [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myLocalImage.png"]];
The error i get is: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage _setAppearanceIsInvalid:]: unrecognized selector sent to instance 0x6876df0'
Anybody can help? (Or is this too nasty of a hack anyway?) Thanks a lot!
Ps: heres the original question for the adding image to navigation bar: how to display an image in the navigation bar of an iPhone application?
Edit: Theres an error in the code: Should be like this i guess:
UIButton* button = (UIButton *) [[UIImageview alloc] initWithImage:myImage];
Anyway, i dont get an error anymore now, but the image does not appear...