Note that there are some explanatory texts on larger screens.

plurals
  1. POImage as rightBarButtonItem from URL
    text
    copied!<p>I try to assign an image loaded via </p> <pre><code>[UIImage imageWithData: [NSData dataWithContentsOfURL:imageUrl]]; </code></pre> <p>to my navigationbar. Here is what i have:</p> <pre><code> //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; </code></pre> <p>This works as long as i take a local image and allocate the image view like this:</p> <pre><code>UIButton* button = (UIButton *) [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myLocalImage.png"]]; </code></pre> <p>The error i get is: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage _setAppearanceIsInvalid:]: unrecognized selector sent to instance 0x6876df0'</p> <p>Anybody can help? (Or is this too nasty of a hack anyway?) Thanks a lot!</p> <p>Ps: heres the original question for the adding image to navigation bar: <a href="https://stackoverflow.com/questions/844416/how-to-display-an-image-in-the-navigation-bar-of-an-iphone-application">how to display an image in the navigation bar of an iPhone application?</a></p> <p><strong>Edit:</strong> Theres an error in the code: Should be like this i guess:</p> <pre><code>UIButton* button = (UIButton *) [[UIImageview alloc] initWithImage:myImage]; </code></pre> <p>Anyway, i dont get an error anymore now, but the image does not appear...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload