• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Asynchronous binding to a remote image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Asynchronous binding to a remote image


  • Subject: Asynchronous binding to a remote image
  • From: Dario Mèndez Musicò <email@hidden>
  • Date: Tue, 27 Sep 2005 16:15:45 +0200

Hello everyone,

I've got a quick (?) question about how to bind an NSImageView to a remote image by it's URL without "freezing" the interface during the process.

I now managed to do it by using an helper method in my NSApp's delegate which "brutally" changes the image.
Needles to say, I don't quite like the way it's done, so I'd like to know if someone has a better idea.
My code is something like this...


ValueTransformer:
@implementation DownloadImageTransformer

+ (Class)transformedValueClass
{
    return [NSImage class];
}

+ (BOOL)allowsReverseTransformation
{
    return NO;
}

- (id)transformedValue:(id)value
{
if ([value isEqualToString: @"N/D"]) {
return [NSImage imageNamed: @"NotAvailable"];
} else {
NSURL *imageURL = [[NSURL alloc] initWithString: value];
[imageURL loadResourceDataNotifyingClient: self usingCache: YES];
return [NSImage imageNamed: @"Wait"];
}
}


- (void)URLResourceDidFinishLoading:(NSURL*)sender
{
//NSLog(@"Image loaded");
[(AppController *)[NSApp delegate] displayGameIcon: [[NSImage alloc] initWithContentsOfURL:sender]];
}


@end

Support method
- (void)displayGameIcon: (NSImage *)gameImage
{
    [gameIcon setImage: gameImage];
}

So basically I take it's URL, check if it is "N/D" (Not Available) and display a notAvailable Image.
If there is an URL I download it using loadResourceDataNotifyingClient:usingCache: in order to keep the UI active in the process.
In the meanwhile I return a "Waiting" image to display a placeholder to inform the user the Image is being download.


After the image is available I put it into the ImageView using the helper method.

It works OK, but I'd like to manage everything without having to use that displayGameIcon: thing, does it sound possible to you?

Thanks in advance





___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Asynchronous binding to a remote image
      • From: Dario Mèndez Musicò <email@hidden>
  • Prev by Date: Re: CFMessagePort to NSMessagePort in IM context?
  • Next by Date: Re: Table Printing
  • Previous by thread: Re: add selectors to a class
  • Next by thread: Re: Asynchronous binding to a remote image
  • Index(es):
    • Date
    • Thread