• 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
Re: Asynchronous binding to a remote image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Asynchronous binding to a remote image


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

Never mind, I solved this already.
If anybody is interested I declared an NSImage in the ValueTransformer interface and returned that Image in the transformedValue: method.


I then released and reallocated it in URLResourceDidFinishLoading:

Works like a charm now :)

Il giorno 27/set/05, alle ore 16:15, Dario Mèndez Musicò ha scritto:

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 10MBhttp://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







___________________________________
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


References: 
 >Asynchronous binding to a remote image (From: Dario Mèndez Musicò <email@hidden>)

  • Prev by Date: Re: Table Printing
  • Next by Date: Re: Table Printing
  • Previous by thread: Asynchronous binding to a remote image
  • Next by thread: Distributed Objects and notficiation
  • Index(es):
    • Date
    • Thread