Re: [iPhone] Caching images fetched from a URL?

2009-05-13 Thread Eric E. Dolecki
Thank you everyone I have this working (locally in memory anyway)... I had to tweak the method a little bit... - (UIImage*)imageNamed:(NSString*)imageNamed cache:(BOOL)cache { UIImage* retImage = [staticImageDictionary objectForKey:imageNamed]; if (retImage == nil) { // Since my

Re: [iPhone] Caching images fetched from a URL?

2009-05-13 Thread Alex Kac
To fix the stutter, use a blank image for when the image doesn't exist - do the NSData dataWithContentsOfURL in another thread so that when it finishes it posts a notification which then the cell will listen to and refresh with the data cached. Its a bit more involved and you have to do

Re: [iPhone] Caching images fetched from a URL?

2009-05-13 Thread Luke the Hiesterman
Be aware that you may run into memory issues if you cache too many images in memory. You should be able to respond to this situation by using UIViewController's didReceiveMemoryWarning method and releasing some of those images. Luke On May 13, 2009, at 6:23 AM, Eric E. Dolecki wrote:

Re: [iPhone] Caching images fetched from a URL?

2009-05-13 Thread Eric E. Dolecki
I have zero experience with threads, and while that does sound good, I don't know how to do that yet. Eric On Wed, May 13, 2009 at 1:06 PM, Alex Kac a...@webis.net wrote: To fix the stutter, use a blank image for when the image doesn't exist - do the NSData dataWithContentsOfURL in another

Re: [iPhone] Caching images fetched from a URL?

2009-05-13 Thread Bradley S. O'Hearne
Take heart, Eric. Threads aren't all that bad -- coding is simple, hardest part is debugging (should your code executing in the new thread is doing something unadvisable), but if you keep it simple, it should be fairly straightforward. Good luck, Brad On May 13, 2009, at 10:36 AM, Eric

Re: [iPhone] Caching images fetched from a URL?

2009-05-13 Thread Eric E. Dolecki
I've just printed out the API docs on NSThread and need to start reading up on it. I assume that's the API I'd want to use. Now, does each image fetch need to be it's own thread (I'm thinking yes). Is there a limit to how many can be going at once? Is the iPhone multi-threaded? I have to figure

Re: [iPhone] Caching images fetched from a URL?

2009-05-13 Thread Luke the Hiesterman
It would be possible to implement one thread that would handle all image download requests, or you could just spin a new thread for each image download. The latter is simpler to code, so I'd lean toward that. There's a limit somewhere on the number of threads in one process, but it's

Re: [iPhone] Caching images fetched from a URL?

2009-05-13 Thread Eric E. Dolecki
So is it safe to approach threads like they were timers? You start a thread, and it calls back to it's selector method when it's complete (detachNewThreadSelector:toTarget:withObject)? Now - what if a thread completes and the cell is currently out of view (it was scrolled) - do the internals take

Re: [iPhone] Caching images fetched from a URL?

2009-05-13 Thread Luke the Hiesterman
On May 13, 2009, at 11:45 AM, Eric E. Dolecki wrote: So is it safe to approach threads like they were timers? You start a thread, and it calls back to it's selector method when it's complete (detachNewThreadSelector:toTarget:withObject)? I would conclude my thread with a line like:

Re: [iPhone] Caching images fetched from a URL?

2009-05-13 Thread Alex Kac
It could cause an error. The way I handle it is this. 1) You have a UIImageView in the cell. 2) Assign it a tag that's unique. imageView.tag = some unique id 3) Since cells are re-used, you need reset the tag in prepareForReuse and make sure to set it in the cellForIndexPath. 4) In the image

Re: [iPhone] Caching images fetched from a URL?

2009-05-13 Thread Eric E. Dolecki
I haven't seen performSelectorOnMainThread before. Should that call go into the selector method that's called? ie... // This kicks off a thread [NSThread detachNewThreadSelector:@selector(threadLoad:) toTarget:self withObject:myArrayWithDictionary]; Now... -(void)threadLoad:(id)param { //

Re: [iPhone] Caching images fetched from a URL?

2009-05-13 Thread Luke the Hiesterman
Yes, something like that. I should mention that it's probably best to send in the NSIndexPath to the cell you're interested in rather than a pointer to the cell itself. Then you can call [tableView cellForRowAtIndexPath:indexPath] to get the cell just before your performeSelectorOnMain

[iPhone] Caching images fetched from a URL?

2009-05-12 Thread Eric E. Dolecki
In my table, when a cell isn't nil I am setting UILabels, etc. However, in each cell I have a UIImageView... and the contents of each is an image fetched from my server. No problem on initial display, but as soon as you start scrolling and the cells are reused, I am fetching new artwork... which

Re: [iPhone] Caching images fetched from a URL?

2009-05-12 Thread Luke the Hiesterman
You should be able to easily implement your own caching mechanism for your content. Keep the images around, either in memory or on disk, as appropriate, and just refresh them when you need to. Luke On May 12, 2009, at 2:04 PM, Eric E. Dolecki wrote: In my table, when a cell isn't nil I am

Re: [iPhone] Caching images fetched from a URL?

2009-05-12 Thread Dave DeLong
Yes, if you cache them yourself. Dave On Tuesday, May 12, 2009, at 03:04PM, Eric E. Dolecki edole...@gmail.com wrote: In my table, when a cell isn't nil I am setting UILabels, etc. However, in each cell I have a UIImageView... and the contents of each is an image fetched from my server. No

Re: [iPhone] Caching images fetched from a URL?

2009-05-12 Thread Eric E. Dolecki
Okay, so I know I can somehow cache them... but I have some noob questions. - how do I cache the images themselves? Some binary data object written to the disk? How? - how do I check if the image has already been loaded (check an NSMutableArray populated with dictionaries with a url string and url

Re: [iPhone] Caching images fetched from a URL?

2009-05-12 Thread Eric Hermanson
Obviously, if you want to cache the images between runs of the application, you need to cache them as binary onto the disk. If you are OK with the images being loaded after every launch of the application, you can cache them into an NSMutableDictionary with the URL as the key, and the

Re: [iPhone] Caching images fetched from a URL?

2009-05-12 Thread Luke the Hiesterman
On May 12, 2009, at 2:13 PM, Eric E. Dolecki wrote: Okay, so I know I can somehow cache them... but I have some noob questions. - how do I cache the images themselves? Some binary data object written to the disk? How? If you're caching to memory, all you really need to do is retain the

Re: [iPhone] Caching images fetched from a URL?

2009-05-12 Thread Bradley S. O'Hearne
Eric, I think one of the more effective ways to cache images is to store your image to the file system, and then store meta-data for that image in a local SQL database. That meta-data should include a last updated date for the image. Then, instead of requesting the image directly from

Re: [iPhone] Caching images fetched from a URL?

2009-05-12 Thread Eric E. Dolecki
I wish that Apple provided a convenient method for doing this as it seems like something that could regularly be employed. I don't think I'll go as far as using SQL, but thanks for all the tips!! On Tue, May 12, 2009 at 7:11 PM, Bradley S. O'Hearne br...@bighillsoftware.com wrote: Eric, I

Re: [iPhone] Caching images fetched from a URL?

2009-05-12 Thread Luke the Hiesterman
On May 12, 2009, at 4:38 PM, Eric E. Dolecki wrote: I wish that Apple provided a convenient method for doing this as it seems like something that could regularly be employed. I don't think I'll go as far as using SQL, but thanks for all the tips!! It doesn't really make sense for Apple to

Re: [iPhone] Caching images fetched from a URL?

2009-05-12 Thread Bradley S. O'Hearne
Eric, For what it is worth -- Luke is right. There are probably so many variations on how developers would want such a cache managed, and the fact that it couldn't be self-contained inside a single API object (or for that matter, tier, as it would require server cooperation too), that it

Re: [iPhone] Caching images fetched from a URL?

2009-05-12 Thread Eric E. Dolecki
I like the cache without writing to the disk (for now anyway). When you say the image object itself, I don't know exactly what you mean... if it's just a pointer to UIImage then I think I do know. So I could pair the pointer with the URL key, is that right? E. On Tue, May 12, 2009 at 5:19 PM,

Re: [iPhone] Caching images fetched from a URL?

2009-05-12 Thread Michael Vannorsdel
The UIImage is the object (inherits from NSObject), so yes you'd pass the pointer to it as the dict's object. And objectForKey: will pass back that pointer to the UIImage again. On May 12, 2009, at 10:00 PM, Eric E. Dolecki wrote: I like the cache without writing to the disk (for now