Brad
Brad

Reputation: 695

Pointer to Pointer to UIImage created by NSURLConnection

Hey all, here's the deal...

I've got a UIImage that is being loaded in the background via an NSURLConnection within a subclassed UIImageView. Until the data finishes downloading, a placeholder image is shown. The UIImage needs to be used by another, separate UIImageView, as well.

The problem I'm having is that if I set the second UIImageView's image property to that of the subclassed object before the download is complete, the second UIImageView never displays the downloaded image, since it's image prop is pointing to the placeholder.

Is there anyway to pass a pointer to a pointer between these two UIImageViews?

I've tried things like this:

imageView2.image = &[imageView1 image];
imageView2.image = *[imageView1 image];

But these don't seem to work. Any ideas?

Upvotes: 0

Views: 613

Answers (2)

Epsilon Prime
Epsilon Prime

Reputation: 4586

Can't you just catch the connectionDidFinishLoading: message from the NSURLConnection and then set the second image?

Upvotes: 0

Marc W
Marc W

Reputation: 19251

Those pointers look particularly gross. The problem with doing it that way is that, even though you might be updating the data pointed to by those pointers, you are not notifying your UIImageView subclasses that the data has changed, and thus they don't know to redraw.

Instead of playing with that pointer mess, why not use Key-Value Observing instead? If you have a separate thread running that downloads the UIImage, you can just tell your UIImageViews to observe that property and when your downloader class is finished downloading all the data and has put it into the property, the views will get a notification and can then display the image.

Upvotes: 2

Related Questions