wigging
wigging

Reputation: 9180

Loading an online GIF image into NSImageView

I can't seem to get an online GIF image to load into an NSImageView. Please see my code below and offer some comments to remedy this.

#import <Foundation/Foundation.h>

@interface ImageFromUrl : NSObject

@property (strong) NSString *urlString;
@property (strong) NSURL *url;
@property (strong) NSImage *radarGif;
@property (weak) IBOutlet NSImageView *radarGifView;

- (void)displayUrlImage:(id)sender;

@end

and

#import "ImageFromUrl.h"

@implementation ImageFromUrl

@synthesize urlString, url, radarGif, radarGifView;

- (void)displayUrlImage:(id)sender {
    urlString = @"http://icons.wunderground.com/data/640x480/2xradarb5.gif";
    url = [NSURL URLWithString:urlString];

    radarGif = [[NSImage alloc] initWithContentsOfURL:url];
    [radarGifView setImage:radarGif];
}

@end

I am receiving no errors when I run the application and the image of the GIF is not showing in the window.

Upvotes: 0

Views: 1098

Answers (1)

rdelmar
rdelmar

Reputation: 104082

I put this code in a project, and it worked fine, so the code works. How did you connect the outlet to the image view (do you have an object in IB that's an instance of this class)? How are you calling the method (and from where)?

Upvotes: 2

Related Questions